Skip to content

Commit

Permalink
replace davinci with 3.5 turbo instruct model
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-risch committed Dec 28, 2023
1 parent 123cfd7 commit a02aafb
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion e2e/pipelines/test_standard_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_webqa_pipeline():
search_key = os.environ.get("SERPERDEV_API_KEY")
openai_key = os.environ.get("OPENAI_API_KEY")
pn = PromptNode(
"text-davinci-003",
"gpt-3.5-turbo-instruct",
api_key=openai_key,
max_length=256,
default_prompt_template="question-answering-with-document-scores",
Expand Down
2 changes: 1 addition & 1 deletion examples/web_lfqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

prompt_node = PromptNode(
"text-davinci-003", default_prompt_template=PromptTemplate(prompt_text), api_key=openai_key, max_length=256
"gpt-3.5-turbo-instruct", default_prompt_template=PromptTemplate(prompt_text), api_key=openai_key, max_length=256
)

web_retriever = WebRetriever(api_key=search_key, top_search_results=5, mode="preprocessed_documents", top_k=30)
Expand Down
2 changes: 1 addition & 1 deletion examples/web_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
raise ValueError("Please set the OPENAI_API_KEY environment variable")

prompt_node = PromptNode(
"text-davinci-003",
"gpt-3.5-turbo-instruct",
api_key=openai_key,
max_length=256,
default_prompt_template="question-answering-with-document-scores",
Expand Down
2 changes: 1 addition & 1 deletion haystack/nodes/prompt/invocation_layer/azure_open_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(
azure_deployment_name: str,
api_key: str,
api_version: str = "2022-12-01",
model_name_or_path: str = "text-davinci-003",
model_name_or_path: str = "gpt-3.5-turbo-instruct",
max_length: Optional[int] = 100,
**kwargs,
):
Expand Down
2 changes: 1 addition & 1 deletion haystack/nodes/prompt/invocation_layer/open_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OpenAIInvocationLayer(PromptModelInvocationLayer):
def __init__(
self,
api_key: str,
model_name_or_path: str = "text-davinci-003",
model_name_or_path: str = "gpt-3.5-turbo-instruct",
max_length: Optional[int] = 100,
api_base: str = "https://api.openai.com/v1",
openai_organization: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion haystack/nodes/sampler/top_p_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TopPSampler(BaseSampler):
```python
prompt_node = PromptNode(
"text-davinci-003",
"gpt-3.5-turbo-instruct",
api_key=openai_key,
max_length=256,
default_prompt_template="question-answering-with-document-scores",
Expand Down
2 changes: 1 addition & 1 deletion test/pipelines/test_standard_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_webqa_pipeline():
search_key = os.environ.get("SERPERDEV_API_KEY")
openai_key = os.environ.get("OPENAI_API_KEY")
pn = PromptNode(
"text-davinci-003",
"gpt-3.5-turbo-instruct",
api_key=openai_key,
max_length=256,
default_prompt_template="question-answering-with-document-scores",
Expand Down
4 changes: 2 additions & 2 deletions test/prompt/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def prompt_model(request, haystack_azure_conf):
api_key = os.environ.get("OPENAI_API_KEY", "KEY_NOT_FOUND")
if api_key is None or api_key == "":
api_key = "KEY_NOT_FOUND"
return PromptModel("text-davinci-003", api_key=api_key)
return PromptModel("gpt-3.5-turbo-instruct", api_key=api_key)
elif request.param == "azure":
api_key = os.environ.get("AZURE_OPENAI_API_KEY", "KEY_NOT_FOUND")
if api_key is None or api_key == "":
api_key = "KEY_NOT_FOUND"
return PromptModel("text-davinci-003", api_key=api_key, model_kwargs=haystack_azure_conf)
return PromptModel("gpt-3.5-turbo-instruct", api_key=api_key, model_kwargs=haystack_azure_conf)
else:
return PromptModel("google/flan-t5-base", devices=["cpu"])

Expand Down
4 changes: 2 additions & 2 deletions test/prompt/invocation_layer/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_openai_token_limit_warning(mock_openai_tokenizer, caplog):
@pytest.mark.parametrize(
"model_name,max_tokens_limit",
[
("text-davinci-003", 4097),
("gpt-3.5-turbo-instruct", 4097),
("gpt-3.5-turbo", 4096),
("gpt-3.5-turbo-16k", 16384),
("gpt-4-32k", 32768),
Expand All @@ -76,7 +76,7 @@ def test_openai_token_limit_warning_not_triggered(caplog, mock_openai_tokenizer,
@pytest.mark.parametrize(
"model_name,max_tokens_limit",
[
("text-davinci-003", 4097),
("gpt-3.5-turbo-instruct", 4097),
("gpt-3.5-turbo", 4096),
("gpt-3.5-turbo-16k", 16384),
("gpt-4-32k", 32768),
Expand Down
8 changes: 4 additions & 4 deletions test/prompt/test_prompt_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ def test_azure_vs_open_ai_invocation_layer_selection():
node = PromptNode("gpt-4", api_key="some_key", model_kwargs=azure_model_kwargs)
assert isinstance(node.prompt_model.model_invocation_layer, AzureChatGPTInvocationLayer)

node = PromptNode("text-davinci-003", api_key="some_key", model_kwargs=azure_model_kwargs)
node = PromptNode("gpt-3.5-turbo-instruct", api_key="some_key", model_kwargs=azure_model_kwargs)
assert isinstance(node.prompt_model.model_invocation_layer, AzureOpenAIInvocationLayer)

node = PromptNode("gpt-4", api_key="some_key")
assert isinstance(node.prompt_model.model_invocation_layer, ChatGPTInvocationLayer) and not isinstance(
node.prompt_model.model_invocation_layer, AzureChatGPTInvocationLayer
)

node = PromptNode("text-davinci-003", api_key="some_key")
node = PromptNode("gpt-3.5-turbo-instruct", api_key="some_key")
assert isinstance(node.prompt_model.model_invocation_layer, OpenAIInvocationLayer) and not isinstance(
node.prompt_model.model_invocation_layer, AzureChatGPTInvocationLayer
)
Expand Down Expand Up @@ -850,7 +850,7 @@ def test_complex_pipeline_with_all_features(tmp_path, haystack_openai_config):
- name: pmodel_openai
type: PromptModel
params:
model_name_or_path: text-davinci-003
model_name_or_path: gpt-3.5-turbo-instruct
model_kwargs:
temperature: 0.9
max_tokens: 64
Expand Down Expand Up @@ -1052,7 +1052,7 @@ def test_content_moderation_gpt_3():
OpenAIInvocationLayer.
"""
prompt_node = PromptNode(
model_name_or_path="text-davinci-003", api_key="key", model_kwargs={"moderate_content": True}
model_name_or_path="gpt-3.5-turbo-instruct", api_key="key", model_kwargs={"moderate_content": True}
)
with patch("haystack.nodes.prompt.invocation_layer.open_ai.check_openai_policy_violation") as mock_check, patch(
"haystack.nodes.prompt.invocation_layer.open_ai.openai_request"
Expand Down
2 changes: 1 addition & 1 deletion test/utils/test_openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_openai_text_completion_tokenization_details_gpt_default():

@pytest.mark.unit
def test_openai_text_completion_tokenization_details_gpt_davinci():
tokenizer_name, max_tokens_limit = _openai_text_completion_tokenization_details(model_name="text-davinci-003")
tokenizer_name, max_tokens_limit = _openai_text_completion_tokenization_details(model_name="gpt-3.5-turbo-instruct")
assert tokenizer_name == "p50k_base"
assert max_tokens_limit == 4097

Expand Down

0 comments on commit a02aafb

Please sign in to comment.