Skip to content

Commit

Permalink
chore: Update OpenAI base URL and model in chat.py, remove commented …
Browse files Browse the repository at this point in the history
…code in page.tsx, and add error handling in main.py
  • Loading branch information
minpeter committed May 29, 2024
1 parent 0ff1b2f commit b56787c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
10 changes: 7 additions & 3 deletions chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

load_dotenv()
friendli_token = os.getenv("FLP_API_KEY")
endpoint = "https://inference-dev.friendli.ai/v1"

client = OpenAI(base_url="https://inference.friendli.ai/v1",

model = "mixtral-8x7b-instruct-v0-1"

client = OpenAI(base_url=endpoint,
api_key=friendli_token)

tools = [
Expand Down Expand Up @@ -35,7 +39,7 @@

def chat_with_tool(messages):
chat = client.chat.completions.create(
model="mixtral-8x7b-instruct-v0-1",
model=model,
messages=messages,
tools=tools,
max_tokens=1000,
Expand Down Expand Up @@ -74,7 +78,7 @@ def chat_with_tool(messages):

def chat(messages):
chat = client.chat.completions.create(
model="mixtral-8x7b-instruct-v0-1",
model=model,
messages=messages,
max_tokens=1000,
)
Expand Down
5 changes: 0 additions & 5 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";

const BodyGoProgramGoProgramPost = {
// Define the schema for your request body here, including required and optional fields
// Example:
question: "",
};

Expand Down Expand Up @@ -44,9 +42,6 @@ function MyComponent() {
throw new Error(`API request failed with status ${response.status}`);
}

// // Handle successful response (e.g., display success message, update state)
// console.log("Request successful:", await response.json()); // Replace with your logic

setResponse(await response.json());
} catch (error: any) {
setError(error?.message); // Set error message for display
Expand Down
8 changes: 7 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ def go_program(question: Annotated[str, Form()], max_retries: Annotated[int, Fo
formated_code = runner_return[1]
retry_count += 1

print("debug")

if run_result == "":
return JSONResponse(content={"error": "Error to run code", "retry_count": retry_count})
return JSONResponse(content={"error": "Error to run code",
"message": "error",
"run_result": "error",
"retry_count": retry_count,
"formated_code": formated_code})

messages.append(
{
Expand Down

0 comments on commit b56787c

Please sign in to comment.