repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import logging |
| #2 | from typing import List |
| #3 | |
| #4 | from app.utils.prompts import MEMORY_CATEGORIZATION_PROMPT |
| #5 | from dotenv import load_dotenv |
| #6 | from openai import OpenAI |
| #7 | from pydantic import BaseModel |
| #8 | from tenacity import retry, stop_after_attempt, wait_exponential |
| #9 | |
| #10 | load_dotenv() |
| #11 | openai_client = OpenAI() |
| #12 | |
| #13 | |
| #14 | class MemoryCategories(BaseModel): |
| #15 | categories: List[str] |
| #16 | |
| #17 | |
| #18 | @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=15)) |
| #19 | def get_categories_for_memory(memory: str) -> List[str]: |
| #20 | try: |
| #21 | messages = [ |
| #22 | {"role": "system", "content": MEMORY_CATEGORIZATION_PROMPT}, |
| #23 | {"role": "user", "content": memory} |
| #24 | ] |
| #25 | |
| #26 | # Let OpenAI handle the pydantic parsing directly |
| #27 | completion = openai_client.beta.chat.completions.parse( |
| #28 | model="gpt-4o-mini", |
| #29 | messages=messages, |
| #30 | response_format=MemoryCategories, |
| #31 | temperature=0 |
| #32 | ) |
| #33 | |
| #34 | parsed: MemoryCategories = completion.choices[0].message.parsed |
| #35 | return [cat.strip().lower() for cat in parsed.categories] |
| #36 | |
| #37 | except Exception as e: |
| #38 | logging.error(f"[ERROR] Failed to get categories: {e}") |
| #39 | try: |
| #40 | logging.debug(f"[DEBUG] Raw response: {completion.choices[0].message.content}") |
| #41 | except Exception as debug_e: |
| #42 | logging.debug(f"[DEBUG] Could not extract raw response: {debug_e}") |
| #43 | raise |
| #44 |