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 AI communication interface #653

Merged
merged 2 commits into from
Dec 22, 2024
Merged

Conversation

Bryan-Roe
Copy link
Collaborator

@Bryan-Roe Bryan-Roe commented Dec 22, 2024

Add AI interaction capability to the web interface.

  • AgentDocs/AssistantFileSearch/Program.cs

    • Add HandleAIInteraction method to handle AI interactions via a web interface.
    • Integrate the method with the existing logic and use OpenAIAssistantAgent for AI communication.
  • app.py

    • Add an endpoint /ai-interact to interact with the AI using the method from AgentDocs/AssistantFileSearch/Program.cs.
    • Ensure the endpoint handles POST requests and returns AI responses in JSON format.
  • config.json

    • Add configuration settings for AI interaction, such as API keys and endpoints.

Summary by Sourcery

New Features:

  • Introduce an AI-powered interactive interface accessible through a new /ai-interact endpoint.

Add AI interaction capability to the web interface.

* **AgentDocs/AssistantFileSearch/Program.cs**
  - Add `HandleAIInteraction` method to handle AI interactions via a web interface.
  - Integrate the method with the existing logic and use `OpenAIAssistantAgent` for AI communication.

* **app.py**
  - Add an endpoint `/ai-interact` to interact with the AI using the method from `AgentDocs/AssistantFileSearch/Program.cs`.
  - Ensure the endpoint handles POST requests and returns AI responses in JSON format.

* **config.json**
  - Add configuration settings for AI interaction, such as API keys and endpoints.
Copy link

sourcery-ai bot commented Dec 22, 2024

Reviewer's Guide by Sourcery

This pull request introduces an AI interaction feature to the web application. It leverages OpenAIAssistantAgent for communication and adds necessary configurations, endpoints, and handling logic.

Sequence diagram for AI interaction flow

sequenceDiagram
    actor User
    participant Web as Web Interface
    participant AI as AI Handler
    participant OpenAI as OpenAI Assistant
    participant Store as Vector Store

    User->>Web: POST /ai-interact
    Web->>AI: HandleAIInteraction(userInput)
    AI->>Store: CreateVectorStore()
    AI->>OpenAI: UploadFiles()
    AI->>OpenAI: CreateAssistant()
    AI->>OpenAI: CreateThread()
    AI->>OpenAI: AddChatMessage(threadId, userInput)
    AI->>OpenAI: InvokeStreaming(threadId)
    OpenAI-->>AI: Stream response chunks
    AI-->>Web: Formatted response
    Web-->>User: JSON response
Loading

Class diagram for AI interaction components

classDiagram
    class Program {
        +HandleAIInteraction(string userInput) Task<string>
    }

    class AIRequest {
        +string user_input
    }

    class FastAPIApp {
        +greet_json()
        +ai_interact(Request, AIRequest) async
    }

    class OpenAIAssistantAgent {
        +CreateAsync()
        +CreateThreadAsync()
        +AddChatMessageAsync()
        +InvokeStreamingAsync()
        +DeleteThreadAsync()
        +DeleteAsync()
    }

    FastAPIApp ..> Program: uses
    FastAPIApp ..> AIRequest: uses
    Program ..> OpenAIAssistantAgent: uses
Loading

File-Level Changes

Change Details Files
Added AI interaction handling.
  • Implemented the HandleAIInteraction method to manage AI interactions through the web interface.
  • Integrated OpenAIAssistantAgent for AI communication.
  • Added logic to load configurations, create a vector store, upload files, define an agent, create a thread, handle user input, and process the AI response including footnotes from the filestore if any.
AgentDocs/AssistantFileSearch/Program.cs
Created a new endpoint for AI interaction.
  • Added the /ai-interact endpoint to handle user interaction with the AI.
  • Implemented POST request handling for the endpoint.
  • Ensured the endpoint returns AI responses in JSON format.
app.py
Added AI configuration settings.
  • Included configuration settings for AI interaction, such as API keys and endpoints.
config.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Bryan-Roe - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The HandleAIInteraction method should use a try-finally block from the start of resource creation to ensure proper cleanup in all scenarios, not just successful execution paths.
  • The /ai-interact endpoint needs request validation and rate limiting to prevent abuse and control costs.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

AgentDocs/AssistantFileSearch/Program.cs Show resolved Hide resolved
app.py Show resolved Hide resolved
* **AgentDocs/AssistantCodeInterpreter/AssistantCodeInterpreter.csproj**
  - Fix formatting issue by removing an extra character at the beginning of the file

* **AgentDocs/AssistantFileSearch/AssistantFileSearch.csproj**
  - Fix formatting issue by adding a newline at the end of the file
@Bryan-Roe Bryan-Roe merged commit 9e4ddbd into main Dec 22, 2024
30 of 120 checks passed
@Bryan-Roe Bryan-Roe deleted the Bryan-Roe/add-ai-communication branch December 22, 2024 21:48
@Bryan-Roe Bryan-Roe restored the Bryan-Roe/add-ai-communication branch December 22, 2024 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant