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

Simple AI mentor chat logic #133

Merged
merged 75 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
7cc84b9
Add GitHub Action workflow
milesha Sep 26, 2024
3604d0f
Merge branch 'develop' into feature/generate-java-client
milesha Sep 30, 2024
96ec9b1
Add generate-java-client
milesha Sep 30, 2024
c0e1119
Store the OpenAPI specifications
milesha Sep 30, 2024
5deb2b0
Fix of FastAPI start
milesha Sep 30, 2024
754c24d
Update devDependencies
milesha Sep 30, 2024
237b891
Update
milesha Sep 30, 2024
a1050a9
Add OpenAPI specification storage
milesha Sep 30, 2024
9e3484c
Delete unnecassary code
milesha Sep 30, 2024
87aae81
Update Git WorkFlow
milesha Sep 30, 2024
9d573cb
Update with right config
milesha Oct 1, 2024
93fb222
Add Java Client
milesha Oct 1, 2024
bc719d1
Upgrade to com.squareup.okio:okio-jvm:3.4.0
milesha Oct 1, 2024
c4f2b44
Add support of the .env file
milesha Oct 1, 2024
4e8098c
Update check-api-client.yml
milesha Oct 1, 2024
27ef5d2
Change the openapi version
milesha Oct 1, 2024
59702a7
Add model configuration for .env
milesha Oct 1, 2024
c2709a6
Change titile
milesha Oct 1, 2024
b862557
Update dependencies
milesha Oct 1, 2024
62ace3f
Delete unused code
milesha Oct 1, 2024
baa1660
Re-name generate function
milesha Oct 1, 2024
955cbeb
Update model config
milesha Oct 1, 2024
987e08e
Format
milesha Oct 1, 2024
cf72601
Change .env usage
milesha Oct 1, 2024
e24285c
Add specification generation
milesha Oct 2, 2024
f496e69
Delete comma crushing the build
milesha Oct 2, 2024
6828d36
Add allow_unicode
milesha Oct 2, 2024
ca11127
Merge branch 'develop' into feature/generate-java-client
milesha Oct 2, 2024
62b7f2d
Delete Java client from the wrong directory
milesha Oct 13, 2024
b2a9513
Add java client gen as a plugin
milesha Oct 14, 2024
be9df1c
Add shx
milesha Oct 23, 2024
edfae58
Add tmp for java client generation
milesha Oct 23, 2024
b181b79
Delete open-api get plugin
milesha Oct 23, 2024
2a92119
Restructure file
milesha Oct 23, 2024
ad55776
Delete unused code
milesha Oct 23, 2024
40b566e
Add generated docs
milesha Oct 25, 2024
4693f32
Fix maven app start error
milesha Oct 25, 2024
e86e211
Merge branch 'develop' into feature/generate-java-client
milesha Oct 25, 2024
475cd01
Add generate all
milesha Oct 25, 2024
ebf90c2
Merge develop
milesha Oct 29, 2024
ddd12be
Restructure and fix bugs
milesha Oct 29, 2024
0a3c1c4
Add new GitHub workflow
milesha Oct 29, 2024
14fba4a
Update generated docs
milesha Oct 29, 2024
98cc49b
Merge branch 'develop' into feature/generate-java-client
milesha Oct 29, 2024
591d1c9
Add Webconfig
milesha Oct 29, 2024
52cbb08
Update naming
milesha Oct 29, 2024
a958122
Fix poetry
milesha Oct 29, 2024
08f2d20
Fix poetry
milesha Oct 29, 2024
a75d1ba
Fix poetry for github workflows
milesha Oct 29, 2024
42e4344
Fix poetry for github workflows
milesha Oct 29, 2024
16c5420
Fix poetry for github workflows
milesha Oct 29, 2024
96e8687
Fix poetry for github workflows
milesha Oct 29, 2024
bde758f
Fix poetry for github workflows
milesha Oct 29, 2024
af5ae94
Fix poetry for github workflows
milesha Oct 29, 2024
e2e9097
Fix MockChatModel bug
milesha Oct 29, 2024
4b4cfe0
Delete autocommit from the workflow
milesha Oct 29, 2024
d76674f
Update and add langgraph
milesha Nov 4, 2024
d4d4b4f
Update congic
milesha Nov 4, 2024
ef9ff36
Add memory and basic prompt integration
milesha Nov 4, 2024
c3718e0
Add langgraph
milesha Nov 4, 2024
274f7c6
Merge branch 'develop' into feature/add-simple-mentor-logic
milesha Nov 4, 2024
ede2d73
Update specs
milesha Nov 4, 2024
05c3798
Change chat description
milesha Nov 4, 2024
8c5a02e
Renamed intelligence api folder
milesha Nov 5, 2024
cc6d73c
Merge branch 'develop' into feature/add-simple-mentor-logic
milesha Nov 5, 2024
e4f6f2e
Run black
milesha Nov 5, 2024
2dc27b5
Delete unused code
milesha Nov 5, 2024
78a5750
Add poetry lock update
milesha Nov 5, 2024
1e3dbe0
Change langgraph version
milesha Nov 5, 2024
00f42ac
chore: update API specs and client
github-actions[bot] Nov 5, 2024
4563fc0
Fix the path
milesha Nov 5, 2024
6980dee
Merge branch 'feature/add-simple-mentor-logic' of https://github.com/…
milesha Nov 5, 2024
19da15d
Merge branch 'develop' into feature/add-simple-mentor-logic
FelixTJDietrich Nov 10, 2024
71e6311
add format scripts
FelixTJDietrich Nov 10, 2024
c964314
fix workflow step name
FelixTJDietrich Nov 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/generate-application-server-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ jobs:
run: |
echo "Removing the autocommit-openapi label..."
curl --silent --fail-with-body -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi
4 changes: 2 additions & 2 deletions .github/workflows/generate-intelligence-service-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

- name: Install Python dependencies
working-directory: server/intelligence-service
run: poetry install --no-interaction --no-root
run: poetry lock --no-update && poetry install --no-interaction --no-root

- name: Generate API client for the application server
working-directory: server/intelligence-service
Expand Down Expand Up @@ -97,4 +97,4 @@ jobs:
run: |
echo "Removing the autocommit-openapi label..."
curl --silent --fail-with-body -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
name: Lint
name: Intelligence Service QA

on: [pull_request]
on:
pull_request:
paths:
- "server/intelligence-service/**"
push:
paths:
- "server/intelligence-service/**"
branches: [develop]

jobs:
lint:
name: Code Quality Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
"generate:api:application-server": "npm run generate:api:application-server-specs && npm run generate:api:application-server:clean && npm run generate:api:application-server-client",
"generate:api:intelligence-service": "npm run generate:api:intelligence-service:clean && npm run generate:api:intelligence-service-specs && npm run generate:api:intelligence-service-client",
"generate:api": "npm run generate:api:intelligence-service && npm run generate:api:application-server",
"prettier:java:check": "prettier --check server/application-server/src/**/*.java",
"prettier:java:write": "prettier --write server/application-server/src/**/*.java",
"format:java:check": "prettier --check server/application-server/src/**/*.java",
"format:java:write": "prettier --write server/application-server/src/**/*.java",
"format:python:check": "cd server/intelligence-service/ && poetry run black --check .",
"format:python:write": "cd server/intelligence-service/ && poetry run black .",
"db:changelog:diff": "cd server/application-server && docker compose up -d postgres && mvn liquibase:diff && docker compose down postgres"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DefaultApi(ApiClient apiClient) {
}

/**
* Get a response from an LLM to a chat message.
* Start and continue a chat session with an LLM.
*
* <p><b>200</b> - Successful Response
* <p><b>422</b> - Validation Error
Expand All @@ -55,7 +55,7 @@ public ChatResponse chatChatPost(ChatRequest chatRequest) throws RestClientExcep
}

/**
* Get a response from an LLM to a chat message.
* Start and continue a chat session with an LLM.
*
* <p><b>200</b> - Successful Response
* <p><b>422</b> - Validation Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
import org.hibernate.validator.constraints.*;
Expand All @@ -28,13 +32,17 @@
* ChatRequest
*/
@JsonPropertyOrder({
ChatRequest.JSON_PROPERTY_MESSAGE
ChatRequest.JSON_PROPERTY_MESSAGE,
ChatRequest.JSON_PROPERTY_THREAD_ID
})
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.7.0")
public class ChatRequest {
public static final String JSON_PROPERTY_MESSAGE = "message";
private String message;

public static final String JSON_PROPERTY_THREAD_ID = "thread_id";
private JsonNullable<String> threadId = JsonNullable.<String>undefined();

public ChatRequest() {
}

Expand Down Expand Up @@ -63,6 +71,39 @@ public void setMessage(String message) {
this.message = message;
}

public ChatRequest threadId(String threadId) {
this.threadId = JsonNullable.<String>of(threadId);

return this;
}

/**
* Get threadId
* @return threadId
*/
@jakarta.annotation.Nullable
@JsonIgnore

public String getThreadId() {
return threadId.orElse(null);
}

@JsonProperty(JSON_PROPERTY_THREAD_ID)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public JsonNullable<String> getThreadId_JsonNullable() {
return threadId;
}

@JsonProperty(JSON_PROPERTY_THREAD_ID)
public void setThreadId_JsonNullable(JsonNullable<String> threadId) {
this.threadId = threadId;
}

public void setThreadId(String threadId) {
this.threadId = JsonNullable.<String>of(threadId);
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -72,19 +113,32 @@ public boolean equals(Object o) {
return false;
}
ChatRequest chatRequest = (ChatRequest) o;
return Objects.equals(this.message, chatRequest.message);
return Objects.equals(this.message, chatRequest.message) &&
equalsNullable(this.threadId, chatRequest.threadId);
}

private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}

@Override
public int hashCode() {
return Objects.hash(message);
return Objects.hash(message, hashCodeNullable(threadId));
}

private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ChatRequest {\n");
sb.append(" message: ").append(toIndentedString(message)).append("\n");
sb.append(" threadId: ").append(toIndentedString(threadId)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
import org.hibernate.validator.constraints.*;
Expand All @@ -28,13 +32,17 @@
* ChatResponse
*/
@JsonPropertyOrder({
ChatResponse.JSON_PROPERTY_RESPONSE
ChatResponse.JSON_PROPERTY_RESPONSE,
ChatResponse.JSON_PROPERTY_THREAD_ID
})
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.7.0")
public class ChatResponse {
public static final String JSON_PROPERTY_RESPONSE = "response";
private String response;

public static final String JSON_PROPERTY_THREAD_ID = "thread_id";
private JsonNullable<String> threadId = JsonNullable.<String>undefined();

public ChatResponse() {
}

Expand Down Expand Up @@ -63,6 +71,39 @@ public void setResponse(String response) {
this.response = response;
}

public ChatResponse threadId(String threadId) {
this.threadId = JsonNullable.<String>of(threadId);

return this;
}

/**
* Get threadId
* @return threadId
*/
@jakarta.annotation.Nullable
@JsonIgnore

public String getThreadId() {
return threadId.orElse(null);
}

@JsonProperty(JSON_PROPERTY_THREAD_ID)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

public JsonNullable<String> getThreadId_JsonNullable() {
return threadId;
}

@JsonProperty(JSON_PROPERTY_THREAD_ID)
public void setThreadId_JsonNullable(JsonNullable<String> threadId) {
this.threadId = threadId;
}

public void setThreadId(String threadId) {
this.threadId = JsonNullable.<String>of(threadId);
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -72,19 +113,32 @@ public boolean equals(Object o) {
return false;
}
ChatResponse chatResponse = (ChatResponse) o;
return Objects.equals(this.response, chatResponse.response);
return Objects.equals(this.response, chatResponse.response) &&
equalsNullable(this.threadId, chatResponse.threadId);
}

private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}

@Override
public int hashCode() {
return Objects.hash(response);
return Objects.hash(response, hashCodeNullable(threadId));
}

private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ChatResponse {\n");
sb.append(" response: ").append(toIndentedString(response)).append("\n");
sb.append(" threadId: ").append(toIndentedString(threadId)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
7 changes: 5 additions & 2 deletions server/intelligence-service/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def is_openai_available(self):

@property
def is_azure_openai_available(self):
return bool(self.AZURE_OPENAI_API_KEY) and bool(self.AZURE_OPENAI_ENDPOINT) and bool(
self.AZURE_OPENAI_API_VERSION)
return (
bool(self.AZURE_OPENAI_API_KEY)
and bool(self.AZURE_OPENAI_ENDPOINT)
and bool(self.AZURE_OPENAI_API_VERSION)
)


settings = Settings()
40 changes: 32 additions & 8 deletions server/intelligence-service/app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from .model import model

from .model import start_chat as start_chat_function, chat as chat_function
from typing import Dict, Optional

app = FastAPI(
title="Hephaestus Intelligence Service API",
Expand All @@ -10,19 +10,43 @@
contact={"name": "Felix T.J. Dietrich", "email": "[email protected]"},
)

# Global dictionary to store conversation states
conversations: Dict[str, dict] = {}


class ChatRequest(BaseModel):
message: str
thread_id: Optional[str] = None


class ChatResponse(BaseModel):
response: str
thread_id: Optional[str] = None


@app.post("/chat", response_model=ChatResponse, summary="Get a response from an LLM to a chat message.")
@app.post(
"/chat",
response_model=ChatResponse,
summary="Start and continue a chat session with an LLM.",
)
async def chat(request: ChatRequest):
try:
response = model.invoke(request.message)
return {"response": response.content}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
if request.thread_id is None:
# Start a new chat session
result = start_chat_function(request.message)
thread_id = result["thread_id"]
state = result["state"]
response_message = result["response"]["messages"][-1].content
conversations[thread_id] = state
return ChatResponse(thread_id=thread_id, response=response_message)
else:
thread_id = request.thread_id
# Check if the thread_id exists
if thread_id not in conversations:
raise HTTPException(status_code=404, detail="Thread ID not found")
state = conversations[thread_id]
user_input = request.message
result = chat_function(thread_id, user_input, state)
state = result["state"]
response_message = result["response"]["messages"][-1].content
conversations[thread_id] = state
return ChatResponse(response=response_message)
Loading
Loading