wenjin272 commented on code in PR #128: URL: https://github.com/apache/flink-agents/pull/128#discussion_r2309130118
########## python/flink_agents/integrations/chat_models/openai/openai_chat_model.py: ########## @@ -0,0 +1,280 @@ +################################################################################ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################# +from typing import Any, Dict, List, Literal, Optional, Sequence + +import httpx +from openai import NOT_GIVEN, OpenAI +from pydantic import Field, PrivateAttr + +from flink_agents.api.chat_message import ChatMessage +from flink_agents.api.chat_models.chat_model import ( + BaseChatModelConnection, + BaseChatModelSetup, +) +from flink_agents.api.tools.tool import BaseTool +from flink_agents.integrations.chat_models.openai.utils import ( + convert_from_openai_message, + convert_to_openai_messages, + resolve_openai_credentials, +) +from flink_agents.integrations.chat_models.utils import to_openai_tool + +DEFAULT_OPENAI_MODEL = "gpt-3.5-turbo" + + +class OpenAIChatModelConnection(BaseChatModelConnection): + """The connection to the OpenAI LLM. + + Attributes: + ---------- + api_key : str + The OpenAI API key. + api_base_url : str + The base URL for OpenAI API. + api_version : str + The API version for OpenAI API. + max_retries : int + The maximum number of API retries. + timeout : float + How long to wait, in seconds, for an API call before failing. + default_headers : Optional[Dict[str, str]] + The default headers for API requests. + reuse_client : bool + Whether to reuse the OpenAI client between requests. + """ + + api_key: str = Field(default=None, description="The OpenAI API key.") + api_base_url: str = Field(description="The base URL for OpenAI API.") + api_version: str = Field(description="The API version for OpenAI API.") Review Comment: This implementation is more likely https://github.com/run-llama/llama_index/tree/main/llama-index-integrations/llms/llama-index-llms-openai-like. I think provide an implementation based on `Chat Completions API` makes sense. There are two main reasons: * Some LLM providers doesn't provide their own API, they only support `Chat Completions API`, like DeepSeek. * It is convenient for user to transfer from different LLM providers. For example, user has used DeepSeek, and he want to transfer to DashScope or OpenAI, he just need modify the `api_base_url`. I agree the strategy that provide one ChatModel implementation per LLM provider. But I think this has no conflict with providing an implementation based on `Chat Completions API`. Perhaps we could modify this implementation name from `OpenAIChatModel` to `OpenAIChatCompletionModel`. And I create the issue #132 which plan to add `OpenAIResponseChatModel`. For other LLM providers which have their own API, we also will provide correspond implementations. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org