Skip to content

Commit

Permalink
fix payload dict chain_config
Browse files Browse the repository at this point in the history
  • Loading branch information
serega-nk committed Nov 14, 2023
1 parent 1667ba7 commit f0512d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 3 additions & 3 deletions examples/giga_chain_api_plus/client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Пример вызова суммаризации статьи "Великий аттрактор" из Википедии"""
import requests

import yaml

with open("chain.yaml", "r", encoding="utf-8") as f:
CHAIN = f.read()
CHAIN_CONFIG = yaml.safe_load(f)

with open("attractor.txt", "r", encoding="utf-8") as f:
TEXT = f.read()
Expand All @@ -14,7 +14,7 @@
# Пример обращения с помощью requests
response = requests.post(
"http://localhost:8000/chain_invoke",
json={"chain_yaml": CHAIN, "input": {"input_document": TEXT}},
json={"chain_config": CHAIN_CONFIG, "input": {"input_document": TEXT}},
timeout=600,
headers={
"Authorization": f"Bearer {ACCESS_TOKEN}",
Expand Down
6 changes: 2 additions & 4 deletions examples/giga_chain_api_plus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from gigachat.exceptions import AuthenticationError
from langchain.pydantic_v1 import BaseModel
from langchain.chains.loading import load_chain_from_config
import yaml
from contextvars_executor import ContextVarExecutor
from gigachat.context import (
authorization_cvar,
Expand Down Expand Up @@ -43,7 +42,7 @@ async def middleware(request, call_next):


class Payload(BaseModel):
chain_yaml: str
chain_config: dict[str, Any]
input: dict[str, Any]


Expand All @@ -53,8 +52,7 @@ class Result(BaseModel):

@app.post("/chain_invoke")
def chain_invoke(payload: Payload) -> Result:
config = yaml.safe_load(payload.chain_yaml)
chain = load_chain_from_config(config)
chain = load_chain_from_config(payload.chain_config)
try:
output = chain.invoke(input=payload.input)
return Result(output=output)
Expand Down

0 comments on commit f0512d5

Please sign in to comment.