fix: changing default model to gpt-4o-mini on OpenAI API calls (#8360)

* chaning default model to gpt-4o-mini

* adding release notes

* fixing some missed tests

* fixing some more missed tests

* fixing one last missed test

* fixing linting issues

* making pylint happy about an end2end test

* chaning if test to walruss operator

* fixing azure embedder from ada to text-embedding-ada-002
This commit is contained in:
David S. Batista
2024-09-17 10:36:42 +02:00
committed by GitHub
parent 9dc602ebf3
commit 97126eb544
15 changed files with 76 additions and 83 deletions
+3 -2
View File
@@ -59,7 +59,7 @@ def rag_pipeline(document_store: InMemoryDocumentStore, top_k: int): # type: ig
rag.add_component("embedder", SentenceTransformersTextEmbedder(model=EMBEDDINGS_MODEL, progress_bar=False)) # type: ignore
rag.add_component("retriever", InMemoryEmbeddingRetriever(document_store, top_k=top_k)) # type: ignore
rag.add_component("prompt_builder", PromptBuilder(template=template)) # type: ignore
rag.add_component("generator", OpenAIGenerator(model="gpt-3.5-turbo")) # type: ignore
rag.add_component("generator", OpenAIGenerator(model="gpt-4o-mini")) # type: ignore
rag.add_component("answer_builder", AnswerBuilder()) # type: ignore
rag.connect("embedder", "retriever.query_embedding")
rag.connect("retriever", "prompt_builder.documents")
@@ -200,7 +200,8 @@ def test_evaluation_pipeline(samples_path):
for article in os.listdir(full_path):
with open(f"{full_path}/{article}", "r") as f:
for text in f.read().split("\n"):
docs.append(Document(content=text, meta={"name": article})) if text else None
if doc := Document(content=text, meta={"name": article}) if text else None:
docs.append(doc)
doc_store = indexing_pipeline(docs)
# running the RAG pipeline A + evaluation pipeline
@@ -58,7 +58,7 @@ class ChatPromptBuilder:
# no parameter init, we don't use any runtime template variables
prompt_builder = ChatPromptBuilder()
llm = OpenAIChatGenerator(api_key=Secret.from_token("<your-api-key>"), model="gpt-3.5-turbo")
llm = OpenAIChatGenerator(api_key=Secret.from_token("<your-api-key>"), model="gpt-4o-mini")
pipe = Pipeline()
pipe.add_component("prompt_builder", prompt_builder)
@@ -76,7 +76,7 @@ class ChatPromptBuilder:
>> {'llm': {'replies': [ChatMessage(content="Berlin is the capital city of Germany and one of the most vibrant
and diverse cities in Europe. Here are some key things to know...Enjoy your time exploring the vibrant and dynamic
capital of Germany!", role=<ChatRole.ASSISTANT: 'assistant'>, name=None, meta={'model': 'gpt-3.5-turbo-0613',
capital of Germany!", role=<ChatRole.ASSISTANT: 'assistant'>, name=None, meta={'model': 'gpt-4o-mini',
'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 27, 'completion_tokens': 681, 'total_tokens':
708}})]}}
@@ -90,7 +90,7 @@ class ChatPromptBuilder:
print(res)
>> {'llm': {'replies': [ChatMessage(content="Here is the weather forecast for Berlin in the next 5
days:\\n\\nDay 1: Mostly cloudy with a high of 22°C (72°F) and...so it's always a good idea to check for updates
closer to your visit.", role=<ChatRole.ASSISTANT: 'assistant'>, name=None, meta={'model': 'gpt-3.5-turbo-0613',
closer to your visit.", role=<ChatRole.ASSISTANT: 'assistant'>, name=None, meta={'model': 'gpt-4o-mini',
'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 37, 'completion_tokens': 201,
'total_tokens': 238}})]}}
```
+4 -4
View File
@@ -40,7 +40,7 @@ class AzureOpenAIGenerator(OpenAIGenerator):
client = AzureOpenAIGenerator(
azure_endpoint="<Your Azure endpoint e.g. `https://your-company.azure.openai.com/>",
api_key=Secret.from_token("<your-api-key>"),
azure_deployment="<this a model name, e.g. gpt-35-turbo>")
azure_deployment="<this a model name, e.g. gpt-4o-mini>")
response = client.run("What's Natural Language Processing? Be brief.")
print(response)
```
@@ -49,7 +49,7 @@ class AzureOpenAIGenerator(OpenAIGenerator):
>> {'replies': ['Natural Language Processing (NLP) is a branch of artificial intelligence that focuses on
>> the interaction between computers and human language. It involves enabling computers to understand, interpret,
>> and respond to natural human language in a way that is both meaningful and useful.'], 'meta': [{'model':
>> 'gpt-3.5-turbo-0613', 'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 16,
>> 'gpt-4o-mini', 'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 16,
>> 'completion_tokens': 49, 'total_tokens': 65}}]}
```
"""
@@ -59,7 +59,7 @@ class AzureOpenAIGenerator(OpenAIGenerator):
self,
azure_endpoint: Optional[str] = None,
api_version: Optional[str] = "2023-05-15",
azure_deployment: Optional[str] = "gpt-35-turbo",
azure_deployment: Optional[str] = "gpt-4o-mini",
api_key: Optional[Secret] = Secret.from_env_var("AZURE_OPENAI_API_KEY", strict=False),
azure_ad_token: Optional[Secret] = Secret.from_env_var("AZURE_OPENAI_AD_TOKEN", strict=False),
organization: Optional[str] = None,
@@ -135,7 +135,7 @@ class AzureOpenAIGenerator(OpenAIGenerator):
self.azure_endpoint = azure_endpoint
self.azure_deployment = azure_deployment
self.organization = organization
self.model: str = azure_deployment or "gpt-35-turbo"
self.model: str = azure_deployment or "gpt-4o-mini"
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", 30.0))
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", 5))
self.default_headers = default_headers or {}
+4 -4
View File
@@ -45,7 +45,7 @@ class AzureOpenAIChatGenerator(OpenAIChatGenerator):
client = AzureOpenAIGenerator(
azure_endpoint="<Your Azure endpoint e.g. `https://your-company.azure.openai.com/>",
api_key=Secret.from_token("<your-api-key>"),
azure_deployment="<this a model name, e.g. gpt-35-turbo>")
azure_deployment="<this a model name, e.g. gpt-4o-mini>")
response = client.run(messages)
print(response)
```
@@ -55,7 +55,7 @@ class AzureOpenAIChatGenerator(OpenAIChatGenerator):
[ChatMessage(content='Natural Language Processing (NLP) is a branch of artificial intelligence that focuses on
enabling computers to understand, interpret, and generate human language in a way that is useful.',
role=<ChatRole.ASSISTANT: 'assistant'>, name=None,
meta={'model': 'gpt-3.5-turbo-0613', 'index': 0, 'finish_reason': 'stop',
meta={'model': 'gpt-4o-mini', 'index': 0, 'finish_reason': 'stop',
'usage': {'prompt_tokens': 15, 'completion_tokens': 36, 'total_tokens': 51}})]
}
```
@@ -66,7 +66,7 @@ class AzureOpenAIChatGenerator(OpenAIChatGenerator):
self,
azure_endpoint: Optional[str] = None,
api_version: Optional[str] = "2023-05-15",
azure_deployment: Optional[str] = "gpt-35-turbo",
azure_deployment: Optional[str] = "gpt-4o-mini",
api_key: Optional[Secret] = Secret.from_env_var("AZURE_OPENAI_API_KEY", strict=False),
azure_ad_token: Optional[Secret] = Secret.from_env_var("AZURE_OPENAI_AD_TOKEN", strict=False),
organization: Optional[str] = None,
@@ -137,7 +137,7 @@ class AzureOpenAIChatGenerator(OpenAIChatGenerator):
self.azure_endpoint = azure_endpoint
self.azure_deployment = azure_deployment
self.organization = organization
self.model = azure_deployment or "gpt-35-turbo"
self.model = azure_deployment or "gpt-4o-mini"
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", 30.0))
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", 5))
self.default_headers = default_headers or {}
@@ -5,7 +5,6 @@
import copy
import json
import os
import warnings
from typing import Any, Callable, Dict, List, Optional, Union
from openai import OpenAI, Stream
@@ -57,7 +56,7 @@ class OpenAIChatGenerator:
that focuses on enabling computers to understand, interpret, and generate human language in
a way that is meaningful and useful.',
role=<ChatRole.ASSISTANT: 'assistant'>, name=None,
meta={'model': 'gpt-3.5-turbo-0613', 'index': 0, 'finish_reason': 'stop',
meta={'model': 'gpt-4o-mini', 'index': 0, 'finish_reason': 'stop',
'usage': {'prompt_tokens': 15, 'completion_tokens': 36, 'total_tokens': 51}})
]
}
@@ -67,7 +66,7 @@ class OpenAIChatGenerator:
def __init__(
self,
api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
model: str = "gpt-3.5-turbo",
model: str = "gpt-4o-mini",
streaming_callback: Optional[Callable[[StreamingChunk], None]] = None,
api_base_url: Optional[str] = None,
organization: Optional[str] = None,
@@ -76,7 +75,7 @@ class OpenAIChatGenerator:
max_retries: Optional[int] = None,
):
"""
Creates an instance of OpenAIChatGenerator. Unless specified otherwise in `model`, uses OpenAI's GPT-3.5.
Creates an instance of OpenAIChatGenerator. Unless specified otherwise in `model`, uses OpenAI's gpt-4o-mini
Before initializing the component, you can set the 'OPENAI_TIMEOUT' and 'OPENAI_MAX_RETRIES'
environment variables to override the `timeout` and `max_retries` parameters respectively
@@ -118,11 +117,6 @@ class OpenAIChatGenerator:
Maximum number of retries to contact OpenAI after an internal error.
If not set, it defaults to either the `OPENAI_MAX_RETRIES` environment variable, or set to 5.
"""
warnings.warn(
"In the upcoming releases 'gpt-3.5-turbo' will be replaced by 'gpt-4o-mini' as the default model",
DeprecationWarning,
)
self.api_key = api_key
self.model = model
self.generation_kwargs = generation_kwargs or {}
+3 -9
View File
@@ -3,7 +3,6 @@
# SPDX-License-Identifier: Apache-2.0
import os
import warnings
from typing import Any, Callable, Dict, List, Optional, Union
from openai import OpenAI, Stream
@@ -45,7 +44,7 @@ class OpenAIGenerator:
>> {'replies': ['Natural Language Processing (NLP) is a branch of artificial intelligence that focuses on
>> the interaction between computers and human language. It involves enabling computers to understand, interpret,
>> and respond to natural human language in a way that is both meaningful and useful.'], 'meta': [{'model':
>> 'gpt-3.5-turbo-0613', 'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 16,
>> 'gpt-4o-mini', 'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 16,
>> 'completion_tokens': 49, 'total_tokens': 65}}]}
```
"""
@@ -53,7 +52,7 @@ class OpenAIGenerator:
def __init__(
self,
api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"),
model: str = "gpt-3.5-turbo",
model: str = "gpt-4o-mini",
streaming_callback: Optional[Callable[[StreamingChunk], None]] = None,
api_base_url: Optional[str] = None,
organization: Optional[str] = None,
@@ -63,7 +62,7 @@ class OpenAIGenerator:
max_retries: Optional[int] = None,
):
"""
Creates an instance of OpenAIGenerator. Unless specified otherwise in `model`, uses OpenAI's GPT-3.5.
Creates an instance of OpenAIGenerator. Unless specified otherwise in `model`, uses OpenAI's gpt-4o-mini
By setting the 'OPENAI_TIMEOUT' and 'OPENAI_MAX_RETRIES' you can change the timeout and max_retries parameters
in the OpenAI client.
@@ -103,11 +102,6 @@ class OpenAIGenerator:
from the `OPENAI_MAX_RETRIES` environment variable or set to 5.
"""
warnings.warn(
"In the upcoming releases 'gpt-3.5-turbo' will be replaced by 'gpt-4o-mini' as the default model",
DeprecationWarning,
)
self.api_key = api_key
self.model = model
self.generation_kwargs = generation_kwargs or {}
+1 -1
View File
@@ -62,7 +62,7 @@ class BranchJoiner:
# Add components to the pipeline
pipe.add_component('joiner', BranchJoiner(List[ChatMessage]))
pipe.add_component('fc_llm', OpenAIChatGenerator(model="gpt-3.5-turbo-0125"))
pipe.add_component('fc_llm', OpenAIChatGenerator(model="gpt-4o-mini"))
pipe.add_component('validator', JsonSchemaValidator(json_schema=person_schema))
pipe.add_component('adapter', OutputAdapter("{{chat_message}}", List[ChatMessage])),
# And connect them
@@ -0,0 +1,4 @@
---
upgrade:
- |
`gpt-3.5-turbo` was replaced by `gpt-4o-mini` as the default model for all components relying on OpenAI API
@@ -160,7 +160,7 @@ class TestAnswerBuilder:
role=ChatRole.ASSISTANT,
name=None,
meta={
"model": "gpt-3.5-turbo-0613",
"model": "gpt-4o-mini",
"index": 0,
"finish_reason": "stop",
"usage": {"prompt_tokens": 32, "completion_tokens": 153, "total_tokens": 185},
@@ -172,7 +172,7 @@ class TestAnswerBuilder:
assert len(answers) == 1
assert answers[0].data == "Answer: AnswerString"
assert answers[0].meta == {
"model": "gpt-3.5-turbo-0613",
"model": "gpt-4o-mini",
"index": 0,
"finish_reason": "stop",
"usage": {"prompt_tokens": 32, "completion_tokens": 153, "total_tokens": 185},
@@ -189,7 +189,7 @@ class TestAnswerBuilder:
role=ChatRole.ASSISTANT,
name=None,
meta={
"model": "gpt-3.5-turbo-0613",
"model": "gpt-4o-mini",
"index": 0,
"finish_reason": "stop",
"usage": {"prompt_tokens": 32, "completion_tokens": 153, "total_tokens": 185},
@@ -201,7 +201,7 @@ class TestAnswerBuilder:
assert len(answers) == 1
assert answers[0].data == "AnswerString"
assert answers[0].meta == {
"model": "gpt-3.5-turbo-0613",
"model": "gpt-4o-mini",
"index": 0,
"finish_reason": "stop",
"usage": {"prompt_tokens": 32, "completion_tokens": 153, "total_tokens": 185},
@@ -218,7 +218,7 @@ class TestAnswerBuilder:
role=ChatRole.ASSISTANT,
name=None,
meta={
"model": "gpt-3.5-turbo-0613",
"model": "gpt-4o-mini",
"index": 0,
"finish_reason": "stop",
"usage": {"prompt_tokens": 32, "completion_tokens": 153, "total_tokens": 185},
@@ -235,7 +235,7 @@ class TestAnswerBuilder:
assert len(answers) == 1
assert answers[0].data == "Answer: AnswerString[2]"
assert answers[0].meta == {
"model": "gpt-3.5-turbo-0613",
"model": "gpt-4o-mini",
"index": 0,
"finish_reason": "stop",
"usage": {"prompt_tokens": 32, "completion_tokens": 153, "total_tokens": 185},
@@ -252,7 +252,7 @@ class TestAnswerBuilder:
role=ChatRole.ASSISTANT,
name=None,
meta={
"model": "gpt-3.5-turbo-0613",
"model": "gpt-4o-mini",
"index": 0,
"finish_reason": "stop",
"usage": {"prompt_tokens": 32, "completion_tokens": 153, "total_tokens": 185},
@@ -264,7 +264,7 @@ class TestAnswerBuilder:
assert len(answers) == 1
assert answers[0].data == "AnswerString"
assert answers[0].meta == {
"model": "gpt-3.5-turbo-0613",
"model": "gpt-4o-mini",
"index": 0,
"finish_reason": "stop",
"usage": {"prompt_tokens": 32, "completion_tokens": 153, "total_tokens": 185},
@@ -81,4 +81,4 @@ class TestAzureOpenAIDocumentEmbedder:
assert isinstance(doc.embedding, list)
assert len(doc.embedding) == 1536
assert all(isinstance(x, float) for x in doc.embedding)
assert metadata == {"model": "ada", "usage": {"prompt_tokens": 15, "total_tokens": 15}}
assert metadata == {"model": "text-embedding-ada-002", "usage": {"prompt_tokens": 15, "total_tokens": 15}}
@@ -59,4 +59,4 @@ class TestAzureOpenAITextEmbedder:
assert len(result["embedding"]) == 1536
assert all(isinstance(x, float) for x in result["embedding"])
assert result["meta"] == {"model": "ada", "usage": {"prompt_tokens": 6, "total_tokens": 6}}
assert result["meta"] == {"model": "text-embedding-ada-002", "usage": {"prompt_tokens": 6, "total_tokens": 6}}
@@ -18,7 +18,7 @@ class TestOpenAIChatGenerator:
monkeypatch.setenv("AZURE_OPENAI_API_KEY", "test-api-key")
component = AzureOpenAIChatGenerator(azure_endpoint="some-non-existing-endpoint")
assert component.client.api_key == "test-api-key"
assert component.azure_deployment == "gpt-35-turbo"
assert component.azure_deployment == "gpt-4o-mini"
assert component.streaming_callback is None
assert not component.generation_kwargs
@@ -36,7 +36,7 @@ class TestOpenAIChatGenerator:
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
)
assert component.client.api_key == "test-api-key"
assert component.azure_deployment == "gpt-35-turbo"
assert component.azure_deployment == "gpt-4o-mini"
assert component.streaming_callback is print_streaming_chunk
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
@@ -51,7 +51,7 @@ class TestOpenAIChatGenerator:
"azure_ad_token": {"env_vars": ["AZURE_OPENAI_AD_TOKEN"], "strict": False, "type": "env_var"},
"api_version": "2023-05-15",
"azure_endpoint": "some-non-existing-endpoint",
"azure_deployment": "gpt-35-turbo",
"azure_deployment": "gpt-4o-mini",
"organization": None,
"streaming_callback": None,
"generation_kwargs": {},
@@ -79,7 +79,7 @@ class TestOpenAIChatGenerator:
"azure_ad_token": {"env_vars": ["ENV_VAR1"], "strict": False, "type": "env_var"},
"api_version": "2023-05-15",
"azure_endpoint": "some-non-existing-endpoint",
"azure_deployment": "gpt-35-turbo",
"azure_deployment": "gpt-4o-mini",
"organization": None,
"streaming_callback": None,
"timeout": 2.5,
@@ -114,7 +114,7 @@ class TestOpenAIChatGenerator:
assert len(results["replies"]) == 1
message: ChatMessage = results["replies"][0]
assert "Paris" in message.content
assert "gpt-35-turbo" in message.meta["model"]
assert "gpt-4o-mini" in message.meta["model"]
assert message.meta["finish_reason"] == "stop"
# additional tests intentionally omitted as they are covered by test_openai.py
+15 -15
View File
@@ -26,7 +26,7 @@ class TestOpenAIChatGenerator:
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
component = OpenAIChatGenerator()
assert component.client.api_key == "test-api-key"
assert component.model == "gpt-3.5-turbo"
assert component.model == "gpt-4o-mini"
assert component.streaming_callback is None
assert not component.generation_kwargs
assert component.client.timeout == 30
@@ -42,7 +42,7 @@ class TestOpenAIChatGenerator:
monkeypatch.setenv("OPENAI_MAX_RETRIES", "10")
component = OpenAIChatGenerator(
api_key=Secret.from_token("test-api-key"),
model="gpt-4",
model="gpt-4o-mini",
streaming_callback=print_streaming_chunk,
api_base_url="test-base-url",
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
@@ -50,7 +50,7 @@ class TestOpenAIChatGenerator:
max_retries=1,
)
assert component.client.api_key == "test-api-key"
assert component.model == "gpt-4"
assert component.model == "gpt-4o-mini"
assert component.streaming_callback is print_streaming_chunk
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
assert component.client.timeout == 40.0
@@ -61,13 +61,13 @@ class TestOpenAIChatGenerator:
monkeypatch.setenv("OPENAI_MAX_RETRIES", "10")
component = OpenAIChatGenerator(
api_key=Secret.from_token("test-api-key"),
model="gpt-4",
model="gpt-4o-mini",
streaming_callback=print_streaming_chunk,
api_base_url="test-base-url",
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
)
assert component.client.api_key == "test-api-key"
assert component.model == "gpt-4"
assert component.model == "gpt-4o-mini"
assert component.streaming_callback is print_streaming_chunk
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
assert component.client.timeout == 100.0
@@ -81,7 +81,7 @@ class TestOpenAIChatGenerator:
"type": "haystack.components.generators.chat.openai.OpenAIChatGenerator",
"init_parameters": {
"api_key": {"env_vars": ["OPENAI_API_KEY"], "strict": True, "type": "env_var"},
"model": "gpt-3.5-turbo",
"model": "gpt-4o-mini",
"organization": None,
"streaming_callback": None,
"api_base_url": None,
@@ -93,7 +93,7 @@ class TestOpenAIChatGenerator:
monkeypatch.setenv("ENV_VAR", "test-api-key")
component = OpenAIChatGenerator(
api_key=Secret.from_env_var("ENV_VAR"),
model="gpt-4",
model="gpt-4o-mini",
streaming_callback=print_streaming_chunk,
api_base_url="test-base-url",
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
@@ -103,7 +103,7 @@ class TestOpenAIChatGenerator:
"type": "haystack.components.generators.chat.openai.OpenAIChatGenerator",
"init_parameters": {
"api_key": {"env_vars": ["ENV_VAR"], "strict": True, "type": "env_var"},
"model": "gpt-4",
"model": "gpt-4o-mini",
"organization": None,
"api_base_url": "test-base-url",
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
@@ -114,7 +114,7 @@ class TestOpenAIChatGenerator:
def test_to_dict_with_lambda_streaming_callback(self, monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
component = OpenAIChatGenerator(
model="gpt-4",
model="gpt-4o-mini",
streaming_callback=lambda x: x,
api_base_url="test-base-url",
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
@@ -124,7 +124,7 @@ class TestOpenAIChatGenerator:
"type": "haystack.components.generators.chat.openai.OpenAIChatGenerator",
"init_parameters": {
"api_key": {"env_vars": ["OPENAI_API_KEY"], "strict": True, "type": "env_var"},
"model": "gpt-4",
"model": "gpt-4o-mini",
"organization": None,
"api_base_url": "test-base-url",
"streaming_callback": "chat.test_openai.<lambda>",
@@ -138,14 +138,14 @@ class TestOpenAIChatGenerator:
"type": "haystack.components.generators.chat.openai.OpenAIChatGenerator",
"init_parameters": {
"api_key": {"env_vars": ["OPENAI_API_KEY"], "strict": True, "type": "env_var"},
"model": "gpt-4",
"model": "gpt-4o-mini",
"api_base_url": "test-base-url",
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
"generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"},
},
}
component = OpenAIChatGenerator.from_dict(data)
assert component.model == "gpt-4"
assert component.model == "gpt-4o-mini"
assert component.streaming_callback is print_streaming_chunk
assert component.api_base_url == "test-base-url"
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
@@ -157,7 +157,7 @@ class TestOpenAIChatGenerator:
"type": "haystack.components.generators.chat.openai.OpenAIChatGenerator",
"init_parameters": {
"api_key": {"env_vars": ["OPENAI_API_KEY"], "strict": True, "type": "env_var"},
"model": "gpt-4",
"model": "gpt-4o-mini",
"organization": None,
"api_base_url": "test-base-url",
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
@@ -279,7 +279,7 @@ class TestOpenAIChatGenerator:
assert len(results["replies"]) == 1
message: ChatMessage = results["replies"][0]
assert "Paris" in message.content
assert "gpt-3.5" in message.meta["model"]
assert "gpt-4o-mini" in message.meta["model"]
assert message.meta["finish_reason"] == "stop"
@pytest.mark.skipif(
@@ -315,7 +315,7 @@ class TestOpenAIChatGenerator:
message: ChatMessage = results["replies"][0]
assert "Paris" in message.content
assert "gpt-3.5" in message.meta["model"]
assert "gpt-4o-mini" in message.meta["model"]
assert message.meta["finish_reason"] == "stop"
assert callback.counter > 1
+6 -6
View File
@@ -18,7 +18,7 @@ class TestAzureOpenAIGenerator:
monkeypatch.setenv("AZURE_OPENAI_API_KEY", "test-api-key")
component = AzureOpenAIGenerator(azure_endpoint="some-non-existing-endpoint")
assert component.client.api_key == "test-api-key"
assert component.azure_deployment == "gpt-35-turbo"
assert component.azure_deployment == "gpt-4o-mini"
assert component.streaming_callback is None
assert not component.generation_kwargs
@@ -32,12 +32,12 @@ class TestAzureOpenAIGenerator:
component = AzureOpenAIGenerator(
api_key=Secret.from_token("fake-api-key"),
azure_endpoint="some-non-existing-endpoint",
azure_deployment="gpt-35-turbo",
azure_deployment="gpt-4o-mini",
streaming_callback=print_streaming_chunk,
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
)
assert component.client.api_key == "fake-api-key"
assert component.azure_deployment == "gpt-35-turbo"
assert component.azure_deployment == "gpt-4o-mini"
assert component.streaming_callback is print_streaming_chunk
assert component.timeout == 30.0
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
@@ -51,7 +51,7 @@ class TestAzureOpenAIGenerator:
"init_parameters": {
"api_key": {"env_vars": ["AZURE_OPENAI_API_KEY"], "strict": False, "type": "env_var"},
"azure_ad_token": {"env_vars": ["AZURE_OPENAI_AD_TOKEN"], "strict": False, "type": "env_var"},
"azure_deployment": "gpt-35-turbo",
"azure_deployment": "gpt-4o-mini",
"api_version": "2023-05-15",
"streaming_callback": None,
"azure_endpoint": "some-non-existing-endpoint",
@@ -81,7 +81,7 @@ class TestAzureOpenAIGenerator:
"init_parameters": {
"api_key": {"env_vars": ["ENV_VAR"], "strict": False, "type": "env_var"},
"azure_ad_token": {"env_vars": ["ENV_VAR1"], "strict": False, "type": "env_var"},
"azure_deployment": "gpt-35-turbo",
"azure_deployment": "gpt-4o-mini",
"api_version": "2023-05-15",
"streaming_callback": None,
"azure_endpoint": "some-non-existing-endpoint",
@@ -121,7 +121,7 @@ class TestAzureOpenAIGenerator:
assert "Paris" in response
metadata = results["meta"][0]
assert "gpt-35-turbo" in metadata["model"]
assert "gpt-4o-mini" in metadata["model"]
assert metadata["finish_reason"] == "stop"
assert "usage" in metadata
+15 -15
View File
@@ -19,7 +19,7 @@ class TestOpenAIGenerator:
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
component = OpenAIGenerator()
assert component.client.api_key == "test-api-key"
assert component.model == "gpt-3.5-turbo"
assert component.model == "gpt-4o-mini"
assert component.streaming_callback is None
assert not component.generation_kwargs
assert component.client.timeout == 30
@@ -35,7 +35,7 @@ class TestOpenAIGenerator:
monkeypatch.setenv("OPENAI_MAX_RETRIES", "10")
component = OpenAIGenerator(
api_key=Secret.from_token("test-api-key"),
model="gpt-4",
model="gpt-4o-mini",
streaming_callback=print_streaming_chunk,
api_base_url="test-base-url",
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
@@ -43,7 +43,7 @@ class TestOpenAIGenerator:
max_retries=1,
)
assert component.client.api_key == "test-api-key"
assert component.model == "gpt-4"
assert component.model == "gpt-4o-mini"
assert component.streaming_callback is print_streaming_chunk
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
assert component.client.timeout == 40.0
@@ -54,13 +54,13 @@ class TestOpenAIGenerator:
monkeypatch.setenv("OPENAI_MAX_RETRIES", "10")
component = OpenAIGenerator(
api_key=Secret.from_token("test-api-key"),
model="gpt-4",
model="gpt-4o-mini",
streaming_callback=print_streaming_chunk,
api_base_url="test-base-url",
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
)
assert component.client.api_key == "test-api-key"
assert component.model == "gpt-4"
assert component.model == "gpt-4o-mini"
assert component.streaming_callback is print_streaming_chunk
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
assert component.client.timeout == 100.0
@@ -74,7 +74,7 @@ class TestOpenAIGenerator:
"type": "haystack.components.generators.openai.OpenAIGenerator",
"init_parameters": {
"api_key": {"env_vars": ["OPENAI_API_KEY"], "strict": True, "type": "env_var"},
"model": "gpt-3.5-turbo",
"model": "gpt-4o-mini",
"streaming_callback": None,
"system_prompt": None,
"api_base_url": None,
@@ -87,7 +87,7 @@ class TestOpenAIGenerator:
monkeypatch.setenv("ENV_VAR", "test-api-key")
component = OpenAIGenerator(
api_key=Secret.from_env_var("ENV_VAR"),
model="gpt-4",
model="gpt-4o-mini",
streaming_callback=print_streaming_chunk,
api_base_url="test-base-url",
organization="org-1234567",
@@ -98,7 +98,7 @@ class TestOpenAIGenerator:
"type": "haystack.components.generators.openai.OpenAIGenerator",
"init_parameters": {
"api_key": {"env_vars": ["ENV_VAR"], "strict": True, "type": "env_var"},
"model": "gpt-4",
"model": "gpt-4o-mini",
"system_prompt": None,
"api_base_url": "test-base-url",
"organization": "org-1234567",
@@ -110,7 +110,7 @@ class TestOpenAIGenerator:
def test_to_dict_with_lambda_streaming_callback(self, monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
component = OpenAIGenerator(
model="gpt-4",
model="gpt-4o-mini",
streaming_callback=lambda x: x,
api_base_url="test-base-url",
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
@@ -120,7 +120,7 @@ class TestOpenAIGenerator:
"type": "haystack.components.generators.openai.OpenAIGenerator",
"init_parameters": {
"api_key": {"env_vars": ["OPENAI_API_KEY"], "strict": True, "type": "env_var"},
"model": "gpt-4",
"model": "gpt-4o-mini",
"system_prompt": None,
"organization": None,
"api_base_url": "test-base-url",
@@ -135,7 +135,7 @@ class TestOpenAIGenerator:
"type": "haystack.components.generators.openai.OpenAIGenerator",
"init_parameters": {
"api_key": {"env_vars": ["OPENAI_API_KEY"], "strict": True, "type": "env_var"},
"model": "gpt-4",
"model": "gpt-4o-mini",
"system_prompt": None,
"organization": None,
"api_base_url": "test-base-url",
@@ -144,7 +144,7 @@ class TestOpenAIGenerator:
},
}
component = OpenAIGenerator.from_dict(data)
assert component.model == "gpt-4"
assert component.model == "gpt-4o-mini"
assert component.streaming_callback is print_streaming_chunk
assert component.api_base_url == "test-base-url"
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
@@ -156,7 +156,7 @@ class TestOpenAIGenerator:
"type": "haystack.components.generators.openai.OpenAIGenerator",
"init_parameters": {
"api_key": {"env_vars": ["OPENAI_API_KEY"], "strict": True, "type": "env_var"},
"model": "gpt-4",
"model": "gpt-4o-mini",
"api_base_url": "test-base-url",
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
"generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"},
@@ -278,7 +278,7 @@ class TestOpenAIGenerator:
assert "Paris" in response
metadata = results["meta"][0]
assert "gpt-3.5" in metadata["model"]
assert "gpt-4o-mini" in metadata["model"]
assert metadata["finish_reason"] == "stop"
assert "usage" in metadata
@@ -322,7 +322,7 @@ class TestOpenAIGenerator:
metadata = results["meta"][0]
assert "gpt-3.5" in metadata["model"]
assert "gpt-4o-mini" in metadata["model"]
assert metadata["finish_reason"] == "stop"
# unfortunately, the usage is not available for streaming calls