Spaces:
Runtime error
Runtime error
Update app.py
Browse files10 unmodified lines111213141516175 unmodified lines2324252627282968 unmodified lines98991001011021031041 unmodified line10610710810911011111276 unmodified lines18919019119219319419520 unmodified lines21621721821922022122210 unmodified lines# from termcolor import colored # doesn't actually work in Colab ¯\_(ツ)_/¯GPT_MODEL = "gpt-3.5-turbo-1106"openai.api_key = os.environ['OPENAI_API_KEY']def exec_python(cell):ipython = get_ipython()5 unmodified lineslog += f"\n{result.error_in_exec}"prompt = """You are a genius math tutor, Python code expert, and a helpful assistant.answer = {ans}Please answer user questions very well with explanations and match it with the multiple choices question.""".format(ans = log)return log68 unmodified linesdef chat_completion_request(messages, functions=None, function_call=None, model=GPT_MODEL):"""This function sends a POST request to the OpenAI API to generate a chat completion.Parameters:- messages (list): A list of message objects. Each object should have a 'role' (either 'system', 'user', or 'assistant') and 'content'(the content of the message).1 unmodified line- function_call (str or dict, optional): If it's a string, it can be either 'auto' (the model decides whether to call a function) or 'none'(the model will not call a function). If it's a dict, it should describe the function to call.- model (str): The ID of the model to use.Returns:- response (requests.Response): The response from the OpenAI API. If the request was successful, the response's JSON will contain the chat completion."""76 unmodified lines# print(result)def second_call(prompt):# Add a new message to the conversation with the function resultmessages.append({"role": "function",20 unmodified linesfirst_call_result, cost1 = first_call(init_prompt, user_input)function_call_process_result = function_call_process(first_call_result)second_prompt_build_result = second_prompt_build(prompt, function_call_process_result)second_call_result, cost2 = second_call(second_prompt_build_result)return first_call_result, function_call_process_result, second_call_result, cost1, cost2def gradio_function():10 unmodified lines11121314151617181920215 unmodified lines27282930313268 unmodified lines1011021031041051061 unmodified line10810911011111211376 unmodified lines19019119219319419519620 unmodified lines21721821922022122222310 unmodified lines# from termcolor import colored # doesn't actually work in Colab ¯\_(ツ)_/¯GPT_MODEL = "gpt-3.5-turbo-1106"from google.colab import userdataopenai.api_key = userdata.get('OPENAI_API_KEY')messages=[]def exec_python(cell):ipython = get_ipython()5 unmodified lineslog += f"\n{result.error_in_exec}"prompt = """You are a genius math tutor, Python code expert, and a helpful assistant.answer = {ans}Please answer user questions very well with explanations and match it with the multiple choices question.""".format(ans = log)return log68 unmodified linesdef chat_completion_request(messages, functions=None, function_call=None, model=GPT_MODEL):"""This function sends a POST request to the OpenAI API to generate a chat completion.Parameters:- messages (list): A list of message objects. Each object should have a 'role' (either 'system', 'user', or 'assistant') and 'content'(the content of the message).1 unmodified line- function_call (str or dict, optional): If it's a string, it can be either 'auto' (the model decides whether to call a function) or 'none'(the model will not call a function). If it's a dict, it should describe the function to call.- model (str): The ID of the model to use.Returns:- response (requests.Response): The response from the OpenAI API. If the request was successful, the response's JSON will contain the chat completion."""76 unmodified lines# print(result)def second_call(prompt, result, function_name = "exec_python"):# Add a new message to the conversation with the function resultmessages.append({"role": "function",20 unmodified linesfirst_call_result, cost1 = first_call(init_prompt, user_input)function_call_process_result = function_call_process(first_call_result)second_prompt_build_result = second_prompt_build(prompt, function_call_process_result)second_call_result, cost2 = second_call(second_prompt_build_result, function_call_process_result)return first_call_result, function_call_process_result, second_call_result, cost1, cost2def gradio_function():
app.py+7-6