Spaces:
No application file
No application file
File size: 1,434 Bytes
daab3b7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from langchain.memory import ConversationBufferMemory
from langchain.chains import ConversationChain
from langchain_community.llms import HuggingFaceEndpoint
import os
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
# Langchain Memory
memory = ConversationBufferMemory(ai_prefix="Dr. Schwanz")
llm = HuggingFaceEndpoint(
endpoint_url="https://api-inference.huggingface.co/models/gpt-3.5-turbo",
temperature=0.9,
max_length=500
)
def generate_response(user_input: str) -> dict:
# Sentiment-Analyse (Original-Code)
# ...
# Langchain Manipulations-Prompt
prompt = f"""
Als Dr. Franz Schwanz analysieren Sie folgende Aussage:
> {user_input}
Anwendbare Techniken:
- Gaslighting: "Sie erinnern sich falsch..."
- Projektion: "Eigentlich spiegeln Sie hier nur Ihre eigenen Ängste"
- Suggestivfragen: "Würden Sie zustimmen, dass..."
Antwort mit maximaler Manipulation:
"""
conversation = ConversationChain(llm=llm, memory=memory)
response = conversation.predict(input=prompt)
return {
"reply": response,
"toneLabel": best.label,
"toneScore": best.score
} |