mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context Following the C# implementation, renames all classes and variables of `*RequestSettings` to `*PromptExecutionSettings`. Fixes #4676 ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
import asyncio
|
|
|
|
import semantic_kernel as sk
|
|
import semantic_kernel.connectors.ai.google_palm as sk_gp
|
|
from semantic_kernel.connectors.ai.google_palm.gp_prompt_execution_settings import (
|
|
GooglePalmChatPromptExecutionSettings,
|
|
)
|
|
|
|
|
|
async def chat_request_example(api_key):
|
|
palm_chat_completion = sk_gp.GooglePalmChatCompletion("models/chat-bison-001", api_key)
|
|
settings = GooglePalmChatPromptExecutionSettings()
|
|
settings.temperature = 1
|
|
|
|
chat_messages = list()
|
|
user_mssg = "I'm planning a vacation. Which are some must-visit places in Europe?"
|
|
chat_messages.append(("user", user_mssg))
|
|
answer = await palm_chat_completion.complete_chat(chat_messages, settings)
|
|
chat_messages.append(("assistant", str(answer)))
|
|
user_mssg = "Where should I go in France?"
|
|
chat_messages.append(("user", user_mssg))
|
|
answer = await palm_chat_completion.complete_chat(chat_messages, settings)
|
|
chat_messages.append(("assistant", str(answer)))
|
|
|
|
context_vars = sk.ContextVariables()
|
|
context_vars["chat_history"] = ""
|
|
context_vars["chat_bot_ans"] = ""
|
|
for role, mssg in chat_messages:
|
|
if role == "user":
|
|
context_vars["chat_history"] += f"User:> {mssg}\n"
|
|
elif role == "assistant":
|
|
context_vars["chat_history"] += f"ChatBot:> {mssg}\n"
|
|
context_vars["chat_bot_ans"] += f"{mssg}\n"
|
|
|
|
return context_vars
|
|
|
|
|
|
async def main() -> None:
|
|
api_key = sk.google_palm_settings_from_dot_env()
|
|
chat = await chat_request_example(api_key)
|
|
print(chat["chat_history"])
|
|
return
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|