move api to state

This commit is contained in:
s444417 2023-06-17 10:44:39 +02:00
parent 44da2b26e2
commit 04868e022d
6 changed files with 16 additions and 8 deletions

View File

@ -2,4 +2,5 @@ RECIPE_PATH=AMUseBotFront/ai_talks/AMUseBotBackend/recipe/
DIALOG_PATH=AMUseBotFront/ai_talks/AMUseBotBackend/dialog/
INTENT_DICT_PATH=ai_talks/AMUseBotBackend/utils/intent_dict.json
MODEL_IDENTIFIER_PATH=ai_talks/AMUseBotBackend/models/NLU/roberta-base-cookdial.txt
INGREDIENTS_RECIPES_MERGED=
INGREDIENTS_RECIPES_MERGED=
API_KEY=

View File

@ -0,0 +1 @@
AMUseBot/roberta-base-cookdial-v1_1

View File

@ -4,14 +4,14 @@ from AMUseBotBackend.src.NLG.nlg import NLG
from AMUseBotBackend.src.tools.search import search_recipe
import AMUseBotBackend.consts as c
import openai
import json
import streamlit as st
class DP:
def __init__(self, dst: DST, llm_rephrasing=False, character='default'): #TODO: a way to set llm_rephrasing status and a character
def __init__(self, dst: DST, llm_rephrasing=True, character='ramsay'): #TODO: a way to set llm_rephrasing status and a character
self.dst_module = dst
self.llm_rephrasing = llm_rephrasing
with open('ai_talks/AMUseBotBackend/utils/characters_dict.json') as f:
@ -21,14 +21,13 @@ class DP:
def llm_rephrase(self, character, response):
model = character['model']
openai.api_key = character['api_key']
prompt = character['prompt']
input = character['leftside_input'] + response + character['rightside_input']
message = [{'role': 'system', 'content': prompt}, {'role': 'user', 'content': input}]
try:
response = openai.ChatCompletion.create(
response = st.session_state.openai.ChatCompletion.create(
model=model, messages=message, temperature=1, max_tokens=128
)
rephrased_response = response.choices[0].message.content

View File

@ -1,10 +1,10 @@
{
"default": {"model": "gpt-3.5-turbo-0613", "api_key": "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", "prompt":
"default": {"model": "gpt-3.5-turbo-0613", "prompt":
"You're a master chef known for treating everyone like your equal. You're currently reading steps of a recipe to your apprentice.",
"leftside_input": "Rephrase this step of a recipe to make it sound more like a natural, full English sentence: '",
"rightside_input": "'."},
"ramsay": {"model": "gpt-3.5-turbo-0613", "api_key": "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", "prompt":
"ramsay": {"model": "gpt-3.5-turbo-0613", "prompt":
"You're Gordon Ramsay, a famous British chef known for his short temper and routinely insulting people. You're currently reading steps of a recipe to your apprentice.",
"leftside_input": "Rephrase this step of a recipe to make it sound as if you said it, in your characteristic rude fashion: '",
"rightside_input": "'."}

View File

@ -9,6 +9,7 @@ import streamlit as st
from PIL import Image
from src.utils.conversation import get_user_input, show_chat_buttons, show_conversation
from src.utils.lang import en
import openai
import os
from dotenv import load_dotenv
@ -43,6 +44,7 @@ if __name__ == '__main__':
DIALOG_PATH = os.getenv('DIALOG_PATH')
RECIPE_PATH = os.getenv('RECIPE_PATH')
API_KEY = os.getenv('API_KEY')
# Storing The Context
if "locale" not in st.session_state:
@ -67,6 +69,10 @@ if __name__ == '__main__':
st.session_state.dst = DST(recipe_path=RECIPE_PATH, dialog_path=DIALOG_PATH)
if "dp" not in st.session_state:
st.session_state.dp = DP(dst=st.session_state.dst)
if "openai" not in st.session_state:
st.session_state.openai = openai
st.session_state.openai.api_key = API_KEY
def show_graph():
# Create a graphlib graph object

View File

@ -23,7 +23,8 @@ def get_nlu_model(intent_dict_path = INTENT_DICT_PATH, model_identifier_path = M
model_identifier_path=model_identifier_path)
def clear_chat() -> None:
st.session_state.generated = []
st.session_state.generated = ["Hello! I'm AMUseBot, a virtual cooking assistant. Please tell me the name of the dish that you'd like to prepare today."]
st.session_state.dst.restart()
st.session_state.past = []
st.session_state.messages = []
st.session_state.user_text = ""