From c93ceb015a1e12d3e0fa7435389efea2e892fc91 Mon Sep 17 00:00:00 2001 From: Oliver Lohmann Date: Wed, 5 Jun 2024 08:45:32 +0200 Subject: [PATCH] true_or_false --- src-agents/phase1/main.py | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src-agents/phase1/main.py b/src-agents/phase1/main.py index 6d349d0..c386e2d 100644 --- a/src-agents/phase1/main.py +++ b/src-agents/phase1/main.py @@ -1,27 +1,18 @@ import os from dotenv import load_dotenv -from fastapi import FastAPI, Response, Request +from fastapi import FastAPI from pydantic import BaseModel from enum import Enum from openai import AzureOpenAI from azure.identity import DefaultAzureCredential, get_bearer_token_provider -from starlette.background import BackgroundTask -from starlette.types import Message -import logging -logging.basicConfig(filename='info.log', level=logging.INFO) app = FastAPI() load_dotenv() -def log_info(req_body, res_body): - logging.info(req_body) - logging.info(res_body) - - class QuestionType(str, Enum): multiple_choice = "multiple_choice" - true_or_false = "true_or_false" + true_false = "true_or_false" popular_choice = "popular_choice" estimation = "estimation" @@ -54,19 +45,6 @@ class Answer(BaseModel): deployment_name = os.getenv("AZURE_OPENAI_COMPLETION_DEPLOYMENT_NAME") -@app.middleware('http') -async def logging_middleware(request: Request, call_next): - req_body = await request.body() - response = await call_next(request) - - res_body = b'' - async for chunk in response.body_iterator: - res_body += chunk - - task = BackgroundTask(log_info, req_body, res_body) - return Response(content=res_body, status_code=response.status_code, - headers=dict(response.headers), media_type=response.media_type, background=task) - @app.get("/") async def root(): return {"message": "Hello Smorgs"} @@ -85,7 +63,7 @@ async def ask_question(ask: Ask): # Send a completion call to generate an answer print('Sending a request to openai') - start_phrase = "Answer the following question. Do only provide the answer, no additional 'a)' or 'b)' or whatever. Question: " + ask.question + start_phrase = ask.question response = client.chat.completions.create( model = deployment_name, messages = [{"role" : "assistant", "content" : start_phrase}], @@ -98,4 +76,4 @@ async def ask_question(ask: Ask): answer.promptTokensUsed = response.usage.prompt_tokens answer.completionTokensUsed = response.usage.completion_tokens - return answer + return answer \ No newline at end of file