Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTPMessangerInterface #410

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Conversation

Ramimashkouk
Copy link
Member

@Ramimashkouk Ramimashkouk commented Dec 5, 2024

Description

Add a new interface HTTPMessangerInterface with an endpoint /chat and health-check one /health

Checklist

  • I have performed a self-review of the changes

List here tasks to complete in order to mark this PR as ready for review.

To Consider

  • Add tests (if functionality is changed)
  • Update API reference / tutorials / guides
  • Update CONTRIBUTING.md (if devel workflow is changed)
  • Update .ignore files, scripts (such as lint), distribution manifest (if files are added/deleted)
  • Search for references to changed entities in the codebase

@Ramimashkouk Ramimashkouk requested a review from RLKRo December 5, 2024 11:51
chatsky/messengers/http_interface.py Outdated Show resolved Hide resolved
Comment on lines 27 to 45
class Output(BaseModel):
user_id: str
response: Message

@app.post("/chat", response_model=Output)
async def respond(
user_id: str,
user_message: Message,
):
message = Message(text=user_message)
context = await pipeline_runner(message, user_id)
return {"user_id": user_id, "response": context.last_response}

@app.get("/health", response_model=HealthStatus)
async def health_check():
return {
"status": "ok",
"uptime": str(time.time() - self.start_time),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to define these (Output, respond, health_check) outside of the connect method and add to the app via

app.post("/chat", response_model=Output)(respond)
app.post("/health", response_model=HealthStatus)(respond)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this's possible, particularly for the respond method as it needs the pipeline_runner unserializable variable. I.e. it's not possible to pass pipeline_runner as a dependency to the endpoint

chatsky/messengers/http_interface.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants