File size: 1,708 Bytes
ade8600
1a45118
ade8600
 
 
3e5a8a4
 
 
7edbd92
6dcfa2f
 
940062f
ade8600
392e10f
ade8600
 
 
907a5fe
ade8600
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
from pydantic import BaseModel
from plugins.sk_bing_plugin import BingPlugin
from plugins.sk_web_pages_plugin import WebPagesPlugin
from planning.autogen_planner import AutoGenPlanner
from web_search_client import WebSearchClient
from web_search_client.models import SafeSearch
from azure.core.credentials import AzureKeyCredential
from semantic_kernel.connectors.ai.openai import OpenAIChatCompletion, AzureChatCompletion
from semantic_kernel.core_skills.text_skill import TextSkill
from semantic_kernel.planning.basic_planner import BasicPlanner

# Configure your credentials here
bing_api_key = "ArAgtjC7LMINRUaY4D6ltro329Po1zNqU82U2JHFDkIbQmzi1_18j71OOdILMdpJ"  # Replace with your Bing API key

llm_config = {
    "type": "openai",  # "azure" or "openai"
    "openai_api_key": "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",  # OpenAI API Key
    "azure_deployment": "",  # Azure OpenAI deployment name
    "azure_api_key": "",  # Azure OpenAI API key in the Azure portal
    "azure_endpoint": ""  # Endpoint URL for Azure OpenAI, e.g. https://contoso.openai.azure.com/
}

kernel = semantic_kernel.Kernel()
kernel.import_skill(BingPlugin(bing_api_key))
kernel.import_skill(WebPagesPlugin())
sk_planner = AutoGenPlanner(kernel, llm_config)
assistant = sk_planner.create_assistant_agent("Assistant")

def get_response(question, max_auto_reply):
    worker = sk_planner.create_user_agent("Worker", max_auto_reply=max_auto_reply, human_input="NEVER")
    worker.initiate_chat(assistant, message=question)
    return worker.get_response()

iface = gr.Interface(fn=get_response, inputs=["text", "number"], outputs="text", inputs_label=["Question", "Max Auto Reply"])
iface.launch()