Skip to content

Commit

Permalink
Merge pull request #16 from shy982/functional-updates
Browse files Browse the repository at this point in the history
Updates to processing logic & Documentation
  • Loading branch information
shy982 authored Dec 11, 2023
2 parents 285fdd1 + f6870f3 commit bed7dc4
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ To run the application (Production build deployment for demo purpose only, not a
3. Wait a while for frontend and backend containers to spawn.
4. Go to http://localhost:3000/ to start chatting

# Notes:
# Repository Handling Notes:

1. Raise PR for Code updates (Anything to src directory)
2. Push to main directly for MOM, References, Presentations, etc
3. Read env.example to create .env for API tokens
4. Mark TODO's as issues
1. Raise PR on separate branch for code updates & request code owner review.
2. Read env.example to create .env for API tokens.
3. Mark TODO's as issues.
64 changes: 64 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,65 @@
# Documentation of APIs, Services, and Modules

# API Documentation

## Overview
This document outlines the available endpoints in the MediMate Q&A application. The application provides endpoints for processing user messages using different methods, including simple text processing, OpenAI's GPT-3.5 model, and a Retrieval-Augmented Generation (RAG) approach.

## Endpoints

### 1. Simple Chat Test
- **Endpoint**: `/v1/chat/simple`
- **Method**: `POST`
- **Description**: A simple test endpoint that capitalizes the last user message. Used primarily for debugging purposes.
- **Request Body**:
- `messages`: Array of message objects. Each message object should contain a `content` key with the message text.
- **Response**: A string with the last message in uppercase.
- **Example Request**:
```json
{
"messages": [
{"content": "hello world"}
]
}
```

### 2. Chat with GPT-3.5 (No RAG)
- **Endpoint**: `/v1/chat/openai`
- **Method**: `POST`
- **Description**: Processes messages using OpenAI's GPT-3.5 model without RAG, considering the entire conversation history.
- **Query Parameters**:
- `model` (optional): Specifies the GPT model to use. Default is "gpt-3.5-turbo-instruct".
- **Request Body**:
- `messages`: Array of message objects as described above.
- `medicalHistory` (optional): String containing the medical history to be considered in the response.
- **Response**: A string containing the AI-generated response.
- **Example Request**:
```json
{
"messages": [
{"content": "What are the symptoms of a cold?"}
],
"medicalHistory": "Patient has a history of allergies."
}
```

### 3. Chat with RAG
- **Endpoint**: `/v1/chat/openai/rag`
- **Method**: `POST`
- **Description**: Processes messages using a RAG approach, combining GPT-3.5 and external knowledge retrieval.
- **Query Parameters**:
- `model` (optional): GPT model to use. Default is "gpt-3.5-turbo-instruct".
- `dataset` (optional): The dataset for knowledge retrieval. Default is "nfcorpus".
- **Request Body**:
- `messages`: Array of message objects as described above.
- `medicalHistory` (optional): String containing relevant medical history.
- **Response**: A string containing the AI-generated response with external knowledge context.
- **Example Request**:
```json
{
"messages": [
{"content": "Tell me about diabetes management."}
],
"medicalHistory": "Patient has type 2 diabetes."
}
```
Binary file removed src/main/.DS_Store
Binary file not shown.
9 changes: 7 additions & 2 deletions src/main/backend/qna_service/openai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
from langchain.schema.output_parser import StrOutputParser
from langchain.schema.runnable import RunnablePassthrough
from langchain.vectorstores import FAISS
import re


def clean_response(response):
cleaned_response = re.sub(r'^\W+', '', response)
return cleaned_response

def request_gpt_no_rag(messages, medical_history, model):
load_dotenv()
client = openai.OpenAI()
Expand All @@ -25,7 +30,7 @@ def request_gpt_no_rag(messages, medical_history, model):
prompt="Answer the last question of this conversation briefly: " + conversation_history,
max_tokens=200
)
return answer.choices[0].text.strip()
return clean_response(answer.choices[0].text.strip()) if answer!= '' else "OpenAI API temporarily down :( Please try again in a while."


def run_rag_pipeline(messages, medical_history, model="gpt-3.5-turbo-instruct", dataset="nfcorpus"):
Expand Down Expand Up @@ -68,4 +73,4 @@ def format_docs(_docs):
# Run the RAG pipeline
response = chain.invoke(conversation_history)

return response.strip()
return clean_response(response.strip()) if response!= '' else "OpenAI API temporarily down :( Please try again in a while."

0 comments on commit bed7dc4

Please sign in to comment.