From ee9a4bffa60ac2b0e26682038352b1f4d12891c8 Mon Sep 17 00:00:00 2001 From: fpagny Date: Wed, 9 Apr 2025 15:10:06 +0200 Subject: [PATCH 1/2] feat(genapi): update faq explaining how multi-turn conversation works with llm --- .../troubleshooting/fixing-common-issues.mdx | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/pages/generative-apis/troubleshooting/fixing-common-issues.mdx b/pages/generative-apis/troubleshooting/fixing-common-issues.mdx index 2240ad6c8b..c24a9b6743 100644 --- a/pages/generative-apis/troubleshooting/fixing-common-issues.mdx +++ b/pages/generative-apis/troubleshooting/fixing-common-issues.mdx @@ -122,6 +122,45 @@ Below are common issues that you may encounter when using Generative APIs, their - Graph across time should be empty ``` +## Previous messages are not taken into account by the model + +### Causes +- Previous messages are not sent to the model +- The content sent exceeds maximum context window for this model + +### Solution +- LLM models are completely "stateless" and thus do not store previous messages or conversations. For example, when building a chatbot application, each time a new message is sent by the user, all preceding messages in the conversation needs to be sent through the API payload. Example payload for multi-turn conversation: +```python +from openai import OpenAI + +client = OpenAI( + base_url="https://api.scaleway.ai/v1", + api_key=os.getenv("SCW_SECRET_KEY") +) + +response = client.chat.completions.create( + model="llama-3.1-8b-instruct", + messages=[ + { + "role": "user", + "content": "What is the solution to 1+1= ?" + }, + { + "role": "assistant", + "content": "2" + }, + { + "role": "user", + "content": "Double this number" + } + ] +) + +print(response.choices[0].message.content) +``` +This snippet will output the model response, which is `4`. +- When exceeding maximum context window, you should receive a `400 - BadRequestError` detailing context length value you exceeded. In this case, you should reduce the size of the content you send to the API. + ## Best practices for optimizing model performance ### Input size management @@ -135,4 +174,4 @@ Below are common issues that you may encounter when using Generative APIs, their ### Debugging silent errors - For cases where no explicit error is returned: - Verify all fields in the API request are correctly named and formatted. - - Test the request with smaller and simpler inputs to isolate potential issues. \ No newline at end of file + - Test the request with smaller and simpler inputs to isolate potential issues. From 5513a4e48e6597d519435fc65fb9041be1be1ad4 Mon Sep 17 00:00:00 2001 From: Benedikt Rollik Date: Thu, 10 Apr 2025 14:42:53 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- .../generative-apis/troubleshooting/fixing-common-issues.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/generative-apis/troubleshooting/fixing-common-issues.mdx b/pages/generative-apis/troubleshooting/fixing-common-issues.mdx index c24a9b6743..5ca250e7d0 100644 --- a/pages/generative-apis/troubleshooting/fixing-common-issues.mdx +++ b/pages/generative-apis/troubleshooting/fixing-common-issues.mdx @@ -126,10 +126,10 @@ Below are common issues that you may encounter when using Generative APIs, their ### Causes - Previous messages are not sent to the model -- The content sent exceeds maximum context window for this model +- The content sent exceeds the maximum context window for this model ### Solution -- LLM models are completely "stateless" and thus do not store previous messages or conversations. For example, when building a chatbot application, each time a new message is sent by the user, all preceding messages in the conversation needs to be sent through the API payload. Example payload for multi-turn conversation: +- LLM models are completely "stateless" and thus do not store previous messages or conversations. For example, when building a chatbot application, each time a new message is sent by the user, all preceding messages in the conversation need to be sent through the API payload. Example payload for multi-turn conversation: ```python from openai import OpenAI