Skip to content

Commit 5b1005f

Browse files
Adding voice ai (#414)
* adding-voice-ai * fixing-example * removing-extra-files * removing-dist
1 parent a696493 commit 5b1005f

File tree

18 files changed

+423
-23
lines changed

18 files changed

+423
-23
lines changed

JS/edgechains/arakoodev/package.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,22 @@
3535
"document": "^0.4.7",
3636
"dts-bundle-generator": "^9.3.1",
3737
"esbuild": "^0.20.2",
38-
"eventsource-parser": "^1.1.2",
39-
"get-port": "^7.1.0",
4038
"hono": "3.9",
4139
"jest-environment-jsdom": "^29.7.0",
4240
"jsdom": "^24.1.0",
43-
"node-fetch": "^3.3.2",
4441
"node-html-parser": "^6.1.13",
45-
"openai": "^4.55.3",
4642
"pdf-parse": "^1.1.1",
4743
"pg": "^8.11.5",
4844
"playwright": "^1.45.1",
4945
"prettier": "^3.2.5",
5046
"regenerator-runtime": "^0.14.1",
5147
"request": "^2.88.2",
48+
"retell-client-js-sdk": "^2.0.4",
49+
"retell-sdk": "^4.7.0",
5250
"retry": "^0.13.1",
53-
"text-encoding": "^0.7.0",
5451
"ts-node": "^10.9.2",
5552
"typeorm": "^0.3.20",
5653
"vitest": "^2.0.3",
57-
"web-streams-polyfill": "^4.0.0",
5854
"youtube-transcript": "^1.2.1",
5955
"zod": "^3.23.8",
6056
"zod-to-json-schema": "^3.23.0"
@@ -66,10 +62,18 @@
6662
"@babel/preset-typescript": "^7.24.1",
6763
"@types/cors": "^2.8.17",
6864
"@types/jest": "^29.5.12",
69-
"@types/node": "^20.13.0",
65+
"@types/node": "^20.17.2",
7066
"@types/pdf-parse": "^1.1.4",
67+
"@types/ws": "^8.5.12",
68+
"buffer": "^6.0.3",
69+
"crypto-browserify": "^3.12.1",
7170
"jest": "^29.7.0",
71+
"process": "^0.11.10",
72+
"stream-browserify": "^3.0.0",
73+
"stream-http": "^3.2.0",
7274
"ts-jest": "^29.1.2",
73-
"typescript": "^5.4.5"
75+
"ts-loader": "^9.5.1",
76+
"typescript": "^5.6.3",
77+
"util": "^0.12.5"
7478
}
7579
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export { OpenAI } from "./lib/openai/openai.js";
22
export { GeminiAI } from "./lib/gemini/gemini.js";
33
export { LlamaAI } from "./lib/llama/llama.js";
4+
export { RetellAI } from "./lib/retell-ai/retell.js";
5+
export { RetellWebClient } from "./lib/retell-ai/retellWebClient.js"

JS/edgechains/arakoodev/src/ai/src/lib/openai/openai.ts

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface OpenAIChatOptions {
2222
temperature?: number;
2323
prompt?: string;
2424
messages?: messageOption[];
25+
frequency_penalty?: number
2526
}
2627

2728
interface chatWithFunctionOptions {
@@ -86,14 +87,15 @@ export class OpenAI {
8687
model: chatOptions.model || "gpt-3.5-turbo",
8788
messages: chatOptions.prompt
8889
? [
89-
{
90-
role: chatOptions.role || "user",
91-
content: chatOptions.prompt,
92-
},
93-
]
90+
{
91+
role: chatOptions.role || "user",
92+
content: chatOptions.prompt,
93+
},
94+
]
9495
: chatOptions.messages,
9596
max_tokens: chatOptions.max_tokens || 256,
9697
temperature: chatOptions.temperature || 0.7,
98+
frequency_penalty: 1,
9799
},
98100
{
99101
headers: {
@@ -119,6 +121,50 @@ export class OpenAI {
119121
return response[0].message;
120122
}
121123

124+
async streamedChat(chatOptions: OpenAIChatOptions): Promise<OpenAIChatReturnOptions> {
125+
const response = await axios
126+
.post(
127+
openAI_url,
128+
{
129+
model: chatOptions.model || "gpt-3.5-turbo",
130+
messages: chatOptions.prompt
131+
? [
132+
{
133+
role: chatOptions.role || "user",
134+
content: chatOptions.prompt,
135+
},
136+
]
137+
: chatOptions.messages,
138+
max_tokens: chatOptions.max_tokens || 256,
139+
temperature: chatOptions.temperature || 0.7,
140+
frequency_penalty: chatOptions.frequency_penalty || 1,
141+
stream: true
142+
},
143+
{
144+
headers: {
145+
Authorization: "Bearer " + this.apiKey,
146+
"content-type": "application/json",
147+
"OpenAI-Organization": this.orgId,
148+
},
149+
}
150+
)
151+
.then((response) => {
152+
return response.data.choices;
153+
})
154+
.catch((error) => {
155+
if (error.response) {
156+
console.log("Server responded with status code:", error.response.status);
157+
console.log("Response data:", error.response.data);
158+
} else if (error.request) {
159+
console.log("No response received:", error);
160+
} else {
161+
console.log("Error creating request:", error.message);
162+
}
163+
});
164+
return response[0].message;
165+
}
166+
167+
122168
async chatWithFunction(
123169
chatOptions: chatWithFunctionOptions
124170
): Promise<chatWithFunctionReturnOptions> {
@@ -129,11 +175,11 @@ export class OpenAI {
129175
model: chatOptions.model || "gpt-3.5-turbo",
130176
messages: chatOptions.prompt
131177
? [
132-
{
133-
role: chatOptions.role || "user",
134-
content: chatOptions.prompt,
135-
},
136-
]
178+
{
179+
role: chatOptions.role || "user",
180+
content: chatOptions.prompt,
181+
},
182+
]
137183
: chatOptions.messages,
138184
max_tokens: chatOptions.max_tokens || 1024,
139185
temperature: chatOptions.temperature || 0.7,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Retell from 'retell-sdk';
2+
import { AgentCreateParams, AgentResponse } from 'retell-sdk/resources/agent.mjs';
3+
import { LlmResponse, LlmCreateParams } from "retell-sdk/resources/llm.mjs";
4+
export class RetellAI {
5+
retellClient: Retell;
6+
llm: null | LlmResponse;
7+
constructor(apiKey: string) {
8+
this.retellClient = new Retell({
9+
apiKey: apiKey,
10+
});
11+
this.llm = null;
12+
}
13+
14+
async createAgent(body: AgentCreateParams, options?: Retell.RequestOptions): Promise<AgentResponse> {
15+
const defaultParams = { voice_id: "11labs-Adrian", agent_name: "Ryan", llm_websocket_url: this?.llm?.llm_websocket_url, }
16+
const keys = Object.keys(defaultParams);
17+
for (let i = 0; i < keys.length; i++) {
18+
if (keys[i] in body) {
19+
delete defaultParams[keys[i]]
20+
}
21+
}
22+
const agent = await this.retellClient.agent.create({ ...defaultParams, ...body }, options);
23+
return agent;
24+
}
25+
async createLLM(data?: LlmCreateParams): Promise<LlmResponse> {
26+
const llm = await this.retellClient.llm.create(data || {});
27+
this.llm = llm;
28+
return llm;
29+
}
30+
31+
async initiateWebCall(agent_id: string): Promise<string> {
32+
const webCallResponse = await this.retellClient.call.createWebCall({ agent_id });
33+
return webCallResponse.access_token
34+
}
35+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { RetellWebClient as RetellClient, StartCallConfig } from "retell-client-js-sdk";
2+
3+
export class RetellWebClient {
4+
client: RetellClient
5+
constructor() {
6+
this.client = new RetellClient();
7+
}
8+
9+
on(event: string, callback: (...args: any[]) => void) {
10+
return this.client.on(event, callback);
11+
}
12+
13+
async startCall(startCallConfig: StartCallConfig) {
14+
return await this.client.startCall(startCallConfig);
15+
}
16+
17+
async stopCall(): Promise<void> {
18+
return this.client.stopCall();
19+
}
20+
}
21+
22+

JS/edgechains/arakoodev/src/index.ts

Whitespace-only changes.

JS/edgechains/arakoodev/src/sync-rpc/lib/sync-rpc.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { execSync } from "child_process";
2-
import path from "path";
3-
import fs from "fs";
4-
import crypto from "crypto";
5-
import os from "os";
1+
import { execSync } from 'node:child_process';
2+
import path from 'node:path';
3+
import fs from 'node:fs';
4+
import crypto from 'node:crypto';
5+
import os from 'node:os';
66

77
function createSyncRPC(filename: string) {
88
const absolutePath = path.resolve(filename);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
.env
4+
.env.local
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 🚀 Welcome to your new awesome project!
2+
3+
This project has been created using **webpack-cli**, you can now run
4+
5+
```
6+
npm run build
7+
```
8+
9+
or
10+
11+
```
12+
yarn build
13+
```
14+
15+
to bundle your application
16+
17+
## How to use
18+
19+
1. Install dependencies
20+
21+
```
22+
npm install
23+
```
24+
25+
2. Run the server
26+
27+
```
28+
npm run start
29+
```
30+
31+
>>>>>>> 100bddc3 (fixing-example)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'htmx.org';
2+
import { RetellWebClient } from "@arakoodev/edgechains.js/ai";
3+
import './style.css';
4+
5+
// Create a single instance
6+
const retellWebClient = new RetellWebClient();
7+
8+
async function startCall(access_token) {
9+
try {
10+
11+
const callResponse = await retellWebClient.startCall({
12+
accessToken: access_token,
13+
});
14+
15+
console.log('Call started:', callResponse);
16+
document.getElementById('callStatus').textContent = 'Call in progress...';
17+
18+
} catch (error) {
19+
console.error('Failed to start call:', error);
20+
document.getElementById('error').textContent = `Failed to start call: ${error.message}`;
21+
}
22+
}
23+
24+
async function endCall() {
25+
try {
26+
await retellWebClient.stopCall();
27+
console.log('Call ended successfully');
28+
document.getElementById('callStatus').textContent = 'Call ended';
29+
} catch (error) {
30+
console.error('Failed to end call:', error);
31+
document.getElementById('error').textContent = `Failed to end call: ${error.message}`;
32+
}
33+
}
34+
35+
// Expose functions to be used with hyperscript or other event handlers
36+
window.startCall = startCall;
37+
window.endCall = endCall;
38+
39+
console.log('Client-side code initialized');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
local general_prompt = "You are a friendly agent that helps people retrieves their questions's answers.";
4+
local begin_message = "Hi, I'm Edgechains agent, how can I help you?";
5+
6+
{
7+
general_prompt: general_prompt,
8+
begin_message: begin_message,
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local RETELL_API_KEY = 'key_****';
2+
3+
{
4+
reteall_api_key: RETELL_API_KEY,
5+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "htmx-webpack-demo",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"build": "webpack",
6+
"dev": "webpack --watch",
7+
"start": "node --experimental-wasm-modules ./server/index.js"
8+
},
9+
"dependencies": {
10+
"@arakoodev/edgechains.js": "file:../../arakoodev",
11+
"@arakoodev/jsonnet": "^0.25.0",
12+
"@hono/node-server": "^1.13.4",
13+
"browserify-zlib": "^0.2.0",
14+
"buffer": "^6.0.3",
15+
"crypto": "^1.0.1",
16+
"crypto-browserify": "^3.12.1",
17+
"file-uri-to-path": "^2.0.0",
18+
"html-webpack-plugin": "^5.6.3",
19+
"htmx.org": "^1.9.10",
20+
"hyperscript": "^2.0.2",
21+
"hyperscript.org": "^0.9.13",
22+
"mini-css-extract-plugin": "^2.9.2",
23+
"process": "^0.11.10",
24+
"retell-client-js-sdk": "^2.0.4",
25+
"retell-sdk": "^4.8.0",
26+
"stream-browserify": "^3.0.0",
27+
"stream-http": "^3.2.0",
28+
"util": "^0.12.5",
29+
"vm-browserify": "^1.1.2",
30+
"vue": "^3.5.12",
31+
"vue-loader": "^17.4.2",
32+
"webpack-node-externals": "^3.0.0",
33+
"workbox-webpack-plugin": "^7.3.0"
34+
},
35+
"devDependencies": {
36+
"@babel/core": "^7.26.0",
37+
"@babel/plugin-transform-runtime": "^7.25.9",
38+
"@babel/preset-env": "^7.26.0",
39+
"assert": "^2.1.0",
40+
"babel-loader": "^9.2.1",
41+
"css-loader": "^7.1.2",
42+
"node-polyfill-webpack-plugin": "^4.0.0",
43+
"os-browserify": "^0.3.0",
44+
"path-browserify": "^1.0.1",
45+
"postcss": "^8.4.47",
46+
"postcss-loader": "^8.1.1",
47+
"postcss-preset-env": "^10.0.9",
48+
"style-loader": "^4.0.0",
49+
"tailwindcss": "^3.4.14",
50+
"url": "^0.11.4",
51+
"webpack": "^5.96.1",
52+
"webpack-cli": "^5.1.4",
53+
"webpack-dev-server": "^5.1.0"
54+
},
55+
"browser": {
56+
"crypto": "crypto-browserify",
57+
"stream": "stream-browserify",
58+
"http": "stream-http",
59+
"util": "util",
60+
"buffer": "buffer",
61+
"node:crypto": "crypto-browserify",
62+
"node:stream": "stream-browserify",
63+
"node:http": "stream-http",
64+
"node:buffer": "buffer",
65+
"node:util": "util"
66+
}
67+
}

0 commit comments

Comments
 (0)