forked from lorenzbaum/Hackathon-Pubquiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.py
69 lines (55 loc) · 1.73 KB
/
quiz.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
from langchain.chat_models import AzureChatOpenAI
from langchain.agents import initialize_agent, AgentType
from langchain.embeddings.azure_openai import AzureOpenAIEmbeddings
from langchain.tools import Tool
from langchain.vectorstores.chroma import Chroma
from openai import AzureOpenAI
from dotenv import load_dotenv
load_dotenv()
# LLM
azure_api_key = os.getenv('AZURE_OPENAI_API_KEY')
azure_endpoint = os.getenv('AZURE_OPENAI_ENDPOINT')
llm = AzureChatOpenAI(
api_key=azure_api_key,
api_version="2023-05-15",
azure_deployment="gpt-35-turbo-16k",
azure_endpoint=azure_endpoint,
)
llm.invoke("What do you know about Pub Quizzes?")
# Chroma db
embeddings = AzureOpenAIEmbeddings(
api_key=azure_api_key,
api_version="2023-05-15",
azure_deployment="text-embedding-ada-002",
azure_endpoint=azure_endpoint,
)
db = Chroma(persist_directory="./PubDatabase/chroma", embedding_function=embeddings)
# Example Agent
qa_tool = Tool.from_function(
func=llm.invoke,
name="QA",
description="Tool to answer a question",
)
PREFIX = """You are participating in a pubquiz. Answer in a short sentence."""
agent = initialize_agent(
tools=[qa_tool],
llm=llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
return_intermediate_steps=True,
handle_parsing_errors=True,
agent_kwargs={
'prefix': PREFIX
}
)
agent.invoke("What do you know about Pub Quizzes?")
# whisper
azure_api_key_whisper = os.getenv('AZURE_OPENAI_API_KEY_WHISPER')
azure_endpoint_whisper = os.getenv('AZURE_OPENAI_ENDPOINT_WHISPER')
whisper = AzureOpenAI(
api_key=azure_api_key_whisper,
azure_endpoint=azure_endpoint_whisper,
azure_deployment="whisper",
api_version="2023-09-01-preview",
)