semantic_kernel.exceptions.kernel_exceptions.KernelInvokeException #5945
-
I try to run this example on https://github.com/microsoft/semantic-kernel/blob/main/python/README.md, but I get this error:
here is the example code: import asyncio
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, AzureChatCompletion
from semantic_kernel.prompt_template import PromptTemplateConfig
from semantic_kernel.utils.settings import openai_settings_from_dot_env, azure_openai_settings_from_dot_env
kernel = Kernel()
# Prepare OpenAI service using credentials stored in the `.env` file
api_key, org_id = "sk-xxx", "xxx"
service_id="chat-gpt"
kernel.add_service(
OpenAIChatCompletion(
service_id=service_id,
ai_model_id="gpt-3.5-turbo",
api_key=api_key,
org_id=org_id
)
)
# Alternative using Azure:
# deployment, api_key, endpoint = azure_openai_settings_from_dot_env()
# kernel.add_service(
# AzureChatCompletion(
# service_id=service_id,
# deployment_name=deployment,
# endpoint=endpoint,
# api_key=api_key
# )
# )
# Define the request settings
req_settings = kernel.get_prompt_execution_settings_from_service_id(service_id)
req_settings.max_tokens = 2000
req_settings.temperature = 0.7
req_settings.top_p = 0.8
prompt = """
1) A robot may not injure a human being or, through inaction,
allow a human being to come to harm.
2) A robot must obey orders given it by human beings except where
such orders would conflict with the First Law.
3) A robot must protect its own existence as long as such protection
does not conflict with the First or Second Law.
Give me the TLDR in exactly 5 words."""
prompt_template_config = PromptTemplateConfig(
template=prompt,
name="tldr",
template_format="semantic-kernel",
execution_settings=req_settings,
)
function = kernel.add_function(
function_name="tldr_function",
plugin_name="tldr_plugin",
prompt_template_config=prompt_template_config,
)
# Run your prompt
# Note: functions are run asynchronously
async def main():
result = await kernel.invoke(function)
print(result) # => Robots must not harm humans.
if __name__ == "__main__":
asyncio.run(main())
# If running from a jupyter-notebook:
# await main() |
Beta Was this translation helpful? Give feedback.
Answered by
sophialagerkranspandey
Apr 23, 2024
Replies: 2 comments
-
@eavanvalkenburg Would you mind taking a look at the above to help with next steps? Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sophialagerkranspandey
-
@adream307 that is pretty old code, for instance the settings are no longer handled that way, see the current samples in the samples directory in python, for the latest and let us know how that goes! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@eavanvalkenburg Would you mind taking a look at the above to help with next steps? Thanks!