Skip to content

Commit 643959e

Browse files
authored
Merge pull request #479 from lmnr-ai/dev
Merge pull request #478 from lmnr-ai/chat-name-fallback
2 parents 917489b + 7de8d10 commit 643959e

File tree

7 files changed

+36
-3
lines changed

7 files changed

+36
-3
lines changed

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ AEAD_SECRET_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
1414

1515
ANTHROPIC_API_KEY=sk-ant-api03-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
1616
SCRAPYBARA_API_KEY=scrapy-01234567-89ab-cdef-0123-456789abcdef
17+
18+
# Uncomment and set this to enable OpenAI support. Currently used in Next.js
19+
# to generate chat names.
20+
# OPENAI_API_KEY

docker-compose-full.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ services:
9595
BACKEND_HTTP_PORT: 8000
9696
BACKEND_GRPC_PORT: 8001
9797
DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
98+
healthcheck:
99+
test: ["CMD", "sleep", "5"]
100+
interval: 10s
101+
timeout: 5s
102+
retries: 1
98103

99104
app-server:
100105
image: ghcr.io/lmnr-ai/app-server
@@ -112,7 +117,7 @@ services:
112117
clickhouse:
113118
condition: service_started
114119
agent-manager:
115-
condition: service_started
120+
condition: service_healthy
116121
environment:
117122
PORT: 8000
118123
GRPC_PORT: 8001
@@ -126,6 +131,7 @@ services:
126131
ENVIRONMENT: FULL
127132
AEAD_SECRET_KEY: ${AEAD_SECRET_KEY}
128133
AGENT_MANAGER_URL: http://agent-manager:8901
134+
129135
frontend:
130136
image: ghcr.io/lmnr-ai/frontend
131137
ports:
@@ -147,6 +153,7 @@ services:
147153
ENVIRONMENT: FULL
148154
CLICKHOUSE_URL: http://clickhouse:8123
149155
CLICKHOUSE_USER: ${CLICKHOUSE_USER}
156+
OPENAI_API_KEY: ${OPENAI_API_KEY}
150157

151158
volumes:
152159
qdrant-data:

docker-compose-local-build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ services:
9292
BACKEND_HTTP_PORT: 8000
9393
BACKEND_GRPC_PORT: 8001
9494
DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
95+
healthcheck:
96+
test: ["CMD", "sleep", "5"]
97+
interval: 10s
98+
timeout: 5s
99+
retries: 1
95100

96101
app-server:
97102
ports:
@@ -114,7 +119,7 @@ services:
114119
python-executor:
115120
condition: service_started
116121
agent-manager:
117-
condition: service_started
122+
condition: service_healthy
118123
environment:
119124
PORT: 8000
120125
GRPC_PORT: 8001
@@ -146,6 +151,7 @@ services:
146151
ENVIRONMENT: FULL
147152
CLICKHOUSE_URL: http://clickhouse:8123
148153
CLICKHOUSE_USER: ${CLICKHOUSE_USER}
154+
OPENAI_API_KEY: ${OPENAI_API_KEY}
149155

150156
volumes:
151157
qdrant-data:

docker-compose.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ services:
6262
ENVIRONMENT: LITE # this disables some runtime dependencies
6363
CLICKHOUSE_URL: http://clickhouse:8123
6464
CLICKHOUSE_USER: ${CLICKHOUSE_USER}
65+
OPENAI_API_KEY: ${OPENAI_API_KEY}
6566

6667
agent-manager:
6768
image: ghcr.io/lmnr-ai/agent-manager
@@ -79,6 +80,12 @@ services:
7980
BACKEND_HTTP_PORT: 8000
8081
BACKEND_GRPC_PORT: 8001
8182
DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
83+
healthcheck:
84+
# naive sleep to ensure agent-manager is ready
85+
test: ["CMD", "sleep", "3"]
86+
interval: 3s
87+
timeout: 5s
88+
retries: 1
8289

8390
app-server:
8491
image: ghcr.io/lmnr-ai/app-server
@@ -92,7 +99,7 @@ services:
9299
clickhouse:
93100
condition: service_started
94101
agent-manager:
95-
condition: service_started
102+
condition: service_healthy
96103
environment:
97104
PORT: 8000
98105
GRPC_PORT: 8001

frontend/.env.local.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ AWS_SECRET_ACCESS_KEY=
3030
S3_TRACE_PAYLOADS_BUCKET=
3131

3232
REDIS_URL=
33+
OPENAI_API_KEY=

frontend/app/api/completion/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { generateText } from "ai";
44
export async function POST(req: Request) {
55
const { prompt }: { prompt: string } = await req.json();
66

7+
if (!process.env.OPENAI_API_KEY) {
8+
return Response.json({ error: "OPENAI_API_KEY is not set" }, { status: 500 });
9+
}
10+
711
const { text } = await generateText({
812
model: openai("gpt-4"),
913
system: "You are a helpful assistant.",

frontend/components/chat/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export const generateChatName = async (input: string) => {
6464
prompt: `Summarize the following message into a brief 3-5 word title, focusing on the main topic or question: "${input}"`,
6565
}),
6666
});
67+
if (!response.ok) {
68+
// Fallback if we couldn't call the language model
69+
return input.slice(0, 50).trim().replace(/["\n]/g, "");
70+
}
6771

6872
const result = (await response.json()) as { text: string };
6973

0 commit comments

Comments
 (0)