Files
semantic-kernel/python/samples/kernel-syntax-examples/plugins_from_dir.py
T
Julio Carlos MenendezandEvan Mattson d97f9536c4 Python: Removes the _async suffix where is not needed (#4735)
### Motivation and Context
Delete all *_async where *_sync doesn't exist to make the library more
Pythonic.

Fixes #4629 

### 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 😄

---------

Co-authored-by: Evan Mattson <[email protected]>
2024-01-26 17:15:35 +00:00

35 lines
1.1 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
import asyncio
import os
import semantic_kernel as sk
import semantic_kernel.connectors.ai.open_ai as sk_oai
kernel = sk.Kernel()
useAzureOpenAI = True
model = "gpt-35-turbo-instruct" if useAzureOpenAI else "gpt-3.5-turbo-instruct"
service_id = model
# Configure AI service used by the kernel
if useAzureOpenAI:
deployment_name, api_key, endpoint = sk.azure_openai_settings_from_dot_env()
kernel.add_text_completion_service(
service_id,
sk_oai.AzureTextCompletion(deployment_name=model, api_key=api_key, endpoint=endpoint),
)
else:
api_key, org_id = sk.openai_settings_from_dot_env()
kernel.add_text_completion_service(
service_id,
sk_oai.OpenAITextCompletion(deployment_name=model, api_key=api_key, org_id=org_id),
)
# note: using plugins from the samples folder
plugins_directory = os.path.join(__file__, "../../../../samples/plugins")
plugin = kernel.import_semantic_plugin_from_directory(plugins_directory, "FunPlugin")
result = asyncio.run(kernel.run(plugin["Joke"], input_str="time travel to dinosaur age"))
print(result)