Add BadJoke GoodJoke data classes
This commit is contained in:
parent
fd7d73e9c3
commit
60d2e4db47
1 changed files with 24 additions and 0 deletions
|
|
@ -1,7 +1,30 @@
|
||||||
import os
|
import os
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from groq import Groq
|
from groq import Groq
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Original: # BadJoke: Sting
|
||||||
|
id: str # should probably be a sha256sum of the title/link?
|
||||||
|
title: str
|
||||||
|
summary: str
|
||||||
|
link: str
|
||||||
|
date: datetime
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Improvement: # GoodJoke: Queen
|
||||||
|
original: Original
|
||||||
|
title: str
|
||||||
|
summary: str
|
||||||
|
id: str = str(uuid4())
|
||||||
|
|
||||||
|
|
||||||
def improve_with_groq(original: str) -> str:
|
def improve_with_groq(original: str) -> str:
|
||||||
client = Groq(api_key=os.getenv("GROQ_API_KEY", "NO_API_KEY_FOUND"))
|
client = Groq(api_key=os.getenv("GROQ_API_KEY", "NO_API_KEY_FOUND"))
|
||||||
|
|
||||||
|
|
@ -52,6 +75,7 @@ app.add_middleware(
|
||||||
def improve_headline(content: str):
|
def improve_headline(content: str):
|
||||||
return improve_with_groq(content)
|
return improve_with_groq(content)
|
||||||
|
|
||||||
|
|
||||||
def read_root():
|
def read_root():
|
||||||
response = {
|
response = {
|
||||||
"data": [
|
"data": [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue