Skip to content

Commit

Permalink
Merge branch 'ts' into fixing-retell
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Raghuwanshi authored Nov 5, 2024
2 parents 36df800 + 5f5c031 commit 7864c7d
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 185 deletions.
2 changes: 1 addition & 1 deletion JS/edgechains/arakoodev/src/ai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export { OpenAI } from "./lib/openai/openai.js";
export { GeminiAI } from "./lib/gemini/gemini.js";
export { LlamaAI } from "./lib/llama/llama.js";
export { RetellAI } from "./lib/retell-ai/retell.js";
export { RetellWebClient } from "./lib/retell-ai/retellWebClient.js"
export { RetellWebClient } from "./lib/retell-ai/retellWebClient.js";
35 changes: 17 additions & 18 deletions JS/edgechains/arakoodev/src/ai/src/lib/openai/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface OpenAIChatOptions {
temperature?: number;
prompt?: string;
messages?: messageOption[];
frequency_penalty?: number
frequency_penalty?: number;
}

interface chatWithFunctionOptions {
Expand Down Expand Up @@ -87,11 +87,11 @@ export class OpenAI {
model: chatOptions.model || "gpt-3.5-turbo",
messages: chatOptions.prompt
? [
{
role: chatOptions.role || "user",
content: chatOptions.prompt,
},
]
{
role: chatOptions.role || "user",
content: chatOptions.prompt,
},
]
: chatOptions.messages,
max_tokens: chatOptions.max_tokens || 256,
temperature: chatOptions.temperature || 0.7,
Expand Down Expand Up @@ -129,16 +129,16 @@ export class OpenAI {
model: chatOptions.model || "gpt-3.5-turbo",
messages: chatOptions.prompt
? [
{
role: chatOptions.role || "user",
content: chatOptions.prompt,
},
]
{
role: chatOptions.role || "user",
content: chatOptions.prompt,
},
]
: chatOptions.messages,
max_tokens: chatOptions.max_tokens || 256,
temperature: chatOptions.temperature || 0.7,
frequency_penalty: chatOptions.frequency_penalty || 1,
stream: true
stream: true,
},
{
headers: {
Expand All @@ -164,7 +164,6 @@ export class OpenAI {
return response[0].message;
}


async chatWithFunction(
chatOptions: chatWithFunctionOptions
): Promise<chatWithFunctionReturnOptions> {
Expand All @@ -175,11 +174,11 @@ export class OpenAI {
model: chatOptions.model || "gpt-3.5-turbo",
messages: chatOptions.prompt
? [
{
role: chatOptions.role || "user",
content: chatOptions.prompt,
},
]
{
role: chatOptions.role || "user",
content: chatOptions.prompt,
},
]
: chatOptions.messages,
max_tokens: chatOptions.max_tokens || 1024,
temperature: chatOptions.temperature || 0.7,
Expand Down
8 changes: 4 additions & 4 deletions JS/edgechains/arakoodev/src/ai/src/lib/retell-ai/retell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Retell from 'retell-sdk';
import { AgentCreateParams, AgentResponse } from 'retell-sdk/resources/agent.mjs';
import Retell from "retell-sdk";
import { AgentCreateParams, AgentResponse } from "retell-sdk/resources/agent.mjs";
import { LlmResponse, LlmCreateParams } from "retell-sdk/resources/llm.mjs";
export class RetellAI {
retellClient: Retell;
Expand All @@ -17,7 +17,7 @@ export class RetellAI {
const keys = Object.keys(defaultParams);
for (let i = 0; i < keys.length; i++) {
if (keys[i] in body) {
delete defaultParams[keys[i]]
delete defaultParams[keys[i]];
}
}
const agent = await this.retellClient.agent.create({ ...defaultParams, ...body }, options);
Expand All @@ -31,6 +31,6 @@ export class RetellAI {

async initiateWebCall(agent_id: string): Promise<string> {
const webCallResponse = await this.retellClient.call.createWebCall({ agent_id });
return webCallResponse.access_token
return webCallResponse.access_token;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RetellWebClient as RetellClient, StartCallConfig } from "retell-client-js-sdk";

export class RetellWebClient {
client: RetellClient
client: RetellClient;
constructor() {
this.client = new RetellClient();
}
Expand All @@ -18,5 +18,3 @@ export class RetellWebClient {
return this.client.stopCall();
}
}


10 changes: 5 additions & 5 deletions JS/edgechains/arakoodev/src/sync-rpc/lib/sync-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { execSync } from 'node:child_process';
import path from 'node:path';
import fs from 'node:fs';
import crypto from 'node:crypto';
import os from 'node:os';
import { execSync } from "node:child_process";
import path from "node:path";
import fs from "node:fs";
import crypto from "node:crypto";
import os from "node:os";

function createSyncRPC(filename: string) {
const absolutePath = path.resolve(filename);
Expand Down
2 changes: 1 addition & 1 deletion JS/edgechains/examples/retell-ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ npm install
npm run start
```

>>>>>>> 100bddc3 (fixing-example)
> > > > > > > 100bddc3 (fixing-example)
24 changes: 11 additions & 13 deletions JS/edgechains/examples/retell-ai/client/index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
import 'htmx.org';
import "htmx.org";
import { RetellWebClient } from "@arakoodev/edgechains.js/ai";
import './style.css';
import "./style.css";

// Create a single instance
const retellWebClient = new RetellWebClient();

async function startCall(access_token) {
try {

const callResponse = await retellWebClient.startCall({
accessToken: access_token,
});

console.log('Call started:', callResponse);
document.getElementById('callStatus').textContent = 'Call in progress...';

console.log("Call started:", callResponse);
document.getElementById("callStatus").textContent = "Call in progress...";
} catch (error) {
console.error('Failed to start call:', error);
document.getElementById('error').textContent = `Failed to start call: ${error.message}`;
console.error("Failed to start call:", error);
document.getElementById("error").textContent = `Failed to start call: ${error.message}`;
}
}

async function endCall() {
try {
await retellWebClient.stopCall();
console.log('Call ended successfully');
document.getElementById('callStatus').textContent = 'Call ended';
console.log("Call ended successfully");
document.getElementById("callStatus").textContent = "Call ended";
} catch (error) {
console.error('Failed to end call:', error);
document.getElementById('error').textContent = `Failed to end call: ${error.message}`;
console.error("Failed to end call:", error);
document.getElementById("error").textContent = `Failed to end call: ${error.message}`;
}
}

// Expose functions to be used with hyperscript or other event handlers
window.startCall = startCall;
window.endCall = endCall;

console.log('Client-side code initialized');
console.log("Client-side code initialized");
130 changes: 65 additions & 65 deletions JS/edgechains/examples/retell-ai/package.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
{
"name": "htmx-webpack-demo",
"version": "1.0.0",
"scripts": {
"build": "webpack",
"dev": "webpack --watch",
"start": "node --experimental-wasm-modules ./server/index.js"
},
"dependencies": {
"@arakoodev/edgechains.js": "file:../../arakoodev",
"@arakoodev/jsonnet": "^0.25.0",
"@hono/node-server": "^1.13.4",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"crypto": "^1.0.1",
"crypto-browserify": "^3.12.1",
"file-uri-to-path": "^2.0.0",
"html-webpack-plugin": "^5.6.3",
"htmx.org": "^1.9.10",
"hyperscript": "^2.0.2",
"hyperscript.org": "^0.9.13",
"mini-css-extract-plugin": "^2.9.2",
"process": "^0.11.10",
"retell-client-js-sdk": "^2.0.4",
"retell-sdk": "^4.8.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"util": "^0.12.5",
"vm-browserify": "^1.1.2",
"vue": "^3.5.12",
"vue-loader": "^17.4.2",
"webpack-node-externals": "^3.0.0",
"workbox-webpack-plugin": "^7.3.0"
},
"devDependencies": {
"@babel/core": "^7.26.0",
"@babel/plugin-transform-runtime": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"assert": "^2.1.0",
"babel-loader": "^9.2.1",
"css-loader": "^7.1.2",
"node-polyfill-webpack-plugin": "^4.0.0",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"postcss": "^8.4.47",
"postcss-loader": "^8.1.1",
"postcss-preset-env": "^10.0.9",
"style-loader": "^4.0.0",
"tailwindcss": "^3.4.14",
"url": "^0.11.4",
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.1.0"
},
"browser": {
"crypto": "crypto-browserify",
"stream": "stream-browserify",
"http": "stream-http",
"util": "util",
"buffer": "buffer",
"node:crypto": "crypto-browserify",
"node:stream": "stream-browserify",
"node:http": "stream-http",
"node:buffer": "buffer",
"node:util": "util"
}
"name": "htmx-webpack-demo",
"version": "1.0.0",
"scripts": {
"build": "webpack",
"dev": "webpack --watch",
"start": "node --experimental-wasm-modules ./server/index.js"
},
"dependencies": {
"@arakoodev/edgechains.js": "file:../../arakoodev",
"@arakoodev/jsonnet": "^0.25.0",
"@hono/node-server": "^1.13.4",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"crypto": "^1.0.1",
"crypto-browserify": "^3.12.1",
"file-uri-to-path": "^2.0.0",
"html-webpack-plugin": "^5.6.3",
"htmx.org": "^1.9.10",
"hyperscript": "^2.0.2",
"hyperscript.org": "^0.9.13",
"mini-css-extract-plugin": "^2.9.2",
"process": "^0.11.10",
"retell-client-js-sdk": "^2.0.4",
"retell-sdk": "^4.8.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"util": "^0.12.5",
"vm-browserify": "^1.1.2",
"vue": "^3.5.12",
"vue-loader": "^17.4.2",
"webpack-node-externals": "^3.0.0",
"workbox-webpack-plugin": "^7.3.0"
},
"devDependencies": {
"@babel/core": "^7.26.0",
"@babel/plugin-transform-runtime": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"assert": "^2.1.0",
"babel-loader": "^9.2.1",
"css-loader": "^7.1.2",
"node-polyfill-webpack-plugin": "^4.0.0",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"postcss": "^8.4.47",
"postcss-loader": "^8.1.1",
"postcss-preset-env": "^10.0.9",
"style-loader": "^4.0.0",
"tailwindcss": "^3.4.14",
"url": "^0.11.4",
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.1.0"
},
"browser": {
"crypto": "crypto-browserify",
"stream": "stream-browserify",
"http": "stream-http",
"util": "util",
"buffer": "buffer",
"node:crypto": "crypto-browserify",
"node:stream": "stream-browserify",
"node:http": "stream-http",
"node:buffer": "buffer",
"node:util": "util"
}
}
7 changes: 2 additions & 5 deletions JS/edgechains/examples/retell-ai/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const tailwindcss = require('tailwindcss');
const tailwindcss = require("tailwindcss");
module.exports = {
plugins: [
'postcss-preset-env',
tailwindcss
],
plugins: ["postcss-preset-env", tailwindcss],
};
32 changes: 15 additions & 17 deletions JS/edgechains/examples/retell-ai/server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"
import { RetellAI } from "@arakoodev/edgechains.js/ai"
import { serveStatic } from '@hono/node-server/serve-static';
import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver";
import { RetellAI } from "@arakoodev/edgechains.js/ai";
import { serveStatic } from "@hono/node-server/serve-static";
import Jsonnet from "@arakoodev/jsonnet";
import path from "path";
import fileURLToPath from "file-uri-to-path";
Expand All @@ -19,19 +19,18 @@ const retellai = new RetellAI(jsonnet_secrets_obj.reteall_api_key);

await retellai.createLLM({
general_prompt: jsonnet_main_obj.general_prompt,
begin_message: jsonnet_main_obj.begin_message
})
begin_message: jsonnet_main_obj.begin_message,
});

const createAgentRes = await retellai.createAgent({});

app.get(
'/static/*',
"/static/*",
serveStatic({
root: './dist',
rewriteRequestPath: (path) =>
path.replace(/^\/static/, '/'),
}))

root: "./dist",
rewriteRequestPath: (path) => path.replace(/^\/static/, "/"),
})
);

app.get("/", (c) => {
return c.html(`<html>
Expand Down Expand Up @@ -59,12 +58,11 @@ app.get("/", (c) => {
</div>
</body>
</html>`);
})

});

app.get("/call", async (c) => {
const token = await retellai.initiateWebCall(createAgentRes.agent_id)
return c.json({ token })
})
const token = await retellai.initiateWebCall(createAgentRes.agent_id);
return c.json({ token });
});

server.listen(3000)
server.listen(3000);
Loading

0 comments on commit 7864c7d

Please sign in to comment.