mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-01-07 04:27:15 +00:00
docs: update ChatMessage examples (#9394)
This commit is contained in:
parent
d8ff508c44
commit
2a64cd4e9a
@ -75,13 +75,13 @@ class ChatPromptBuilder:
|
||||
"template": messages}})
|
||||
print(res)
|
||||
|
||||
>> {'llm': {'replies': [ChatMessage(content="Berlin is the capital city of Germany and one of the most vibrant
|
||||
>> {'llm': {'replies': [ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>, _content=[TextContent(text=
|
||||
"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-4o-mini',
|
||||
capital of Germany!")], _name=None, _meta={'model': 'gpt-4o-mini',
|
||||
'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 27, 'completion_tokens': 681, 'total_tokens':
|
||||
708}})]}}
|
||||
|
||||
|
||||
messages = [system_message, ChatMessage.from_user("What's the weather forecast for {{location}} in the next
|
||||
{{day_count}} days?")]
|
||||
|
||||
@ -89,9 +89,10 @@ class ChatPromptBuilder:
|
||||
"template": messages}})
|
||||
|
||||
print(res)
|
||||
>> {'llm': {'replies': [ChatMessage(content="Here is the weather forecast for Berlin in the next 5
|
||||
>> {'llm': {'replies': [ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>, _content=[TextContent(text=
|
||||
"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-4o-mini',
|
||||
closer to your visit.")], _name=None, _meta={'model': 'gpt-4o-mini',
|
||||
'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 37, 'completion_tokens': 201,
|
||||
'total_tokens': 238}})]}}
|
||||
```
|
||||
|
||||
@ -188,7 +188,8 @@ class OpenAPIServiceConnector:
|
||||
service_openapi_spec=serperdev_openapi_spec, service_credentials=serper_token)
|
||||
print(result)
|
||||
|
||||
>> {'service_response': [ChatMessage(content='{"searchParameters": {"q": "Why was Sam Altman ousted from OpenAI?",
|
||||
>> {'service_response': [ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>, _content=[TextContent(text=
|
||||
>> '{"searchParameters": {"q": "Why was Sam Altman ousted from OpenAI?",
|
||||
>> "type": "search", "engine": "google"}, "answerBox": {"snippet": "Concerns over AI safety and OpenAI\'s role
|
||||
>> in protecting were at the center of Altman\'s brief ouster from the company."...
|
||||
```
|
||||
|
||||
@ -57,10 +57,11 @@ class AzureOpenAIChatGenerator(OpenAIChatGenerator):
|
||||
|
||||
```
|
||||
{'replies':
|
||||
[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-4o-mini', 'index': 0, 'finish_reason': 'stop',
|
||||
[ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>, _content=[TextContent(text=
|
||||
"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.")],
|
||||
_name=None,
|
||||
_meta={'model': 'gpt-4o-mini', 'index': 0, 'finish_reason': 'stop',
|
||||
'usage': {'prompt_tokens': 15, 'completion_tokens': 36, 'total_tokens': 51}})]
|
||||
}
|
||||
```
|
||||
|
||||
@ -105,14 +105,14 @@ class HuggingFaceLocalChatGenerator:
|
||||
|
||||
```
|
||||
{'replies':
|
||||
[ChatMessage(content=' Natural Language Processing (NLP) is a subfield of artificial intelligence that deals
|
||||
[ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>, _content=[TextContent(text=
|
||||
"Natural Language Processing (NLP) is a subfield of artificial intelligence that deals
|
||||
with the interaction between computers and human language. It enables computers to understand, interpret, and
|
||||
generate human language in a valuable way. NLP involves various techniques such as speech recognition, text
|
||||
analysis, sentiment analysis, and machine translation. The ultimate goal is to make it easier for computers to
|
||||
process and derive meaning from human language, improving communication between humans and machines.',
|
||||
role=<ChatRole.ASSISTANT: 'assistant'>,
|
||||
name=None,
|
||||
meta={'finish_reason': 'stop', 'index': 0, 'model':
|
||||
process and derive meaning from human language, improving communication between humans and machines.")],
|
||||
_name=None,
|
||||
_meta={'finish_reason': 'stop', 'index': 0, 'model':
|
||||
'mistralai/Mistral-7B-Instruct-v0.2',
|
||||
'usage': {'completion_tokens': 90, 'prompt_tokens': 19, 'total_tokens': 109}})
|
||||
]
|
||||
|
||||
@ -67,11 +67,12 @@ class OpenAIChatGenerator:
|
||||
Output:
|
||||
```
|
||||
{'replies':
|
||||
[ChatMessage(content='Natural Language Processing (NLP) is a branch of artificial intelligence
|
||||
[ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>, _content=
|
||||
[TextContent(text="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 meaningful and useful.',
|
||||
role=<ChatRole.ASSISTANT: 'assistant'>, name=None,
|
||||
meta={'model': 'gpt-4o-mini', 'index': 0, 'finish_reason': 'stop',
|
||||
a way that is meaningful and useful.")],
|
||||
_name=None,
|
||||
_meta={'model': 'gpt-4o-mini', 'index': 0, 'finish_reason': 'stop',
|
||||
'usage': {'prompt_tokens': 15, 'completion_tokens': 36, 'total_tokens': 51}})
|
||||
]
|
||||
}
|
||||
|
||||
@ -81,8 +81,9 @@ class JsonSchemaValidator:
|
||||
}
|
||||
})
|
||||
print(result)
|
||||
>> {'schema_validator': {'validated': [ChatMessage(content='\\n{\\n "name": "John",\\n "age": 30\\n}',
|
||||
role=<ChatRole.ASSISTANT: 'assistant'>, name=None, meta={'model': 'gpt-4-1106-preview', 'index': 0,
|
||||
>> {'schema_validator': {'validated': [ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>,
|
||||
_content=[TextContent(text="\\n{\\n "name": "John",\\n "age": 30\\n}")],
|
||||
_name=None, _meta={'model': 'gpt-4-1106-preview', 'index': 0,
|
||||
'finish_reason': 'stop', 'usage': {'completion_tokens': 17, 'prompt_tokens': 20, 'total_tokens': 37}})]}}
|
||||
```
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user