mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
Refactor: Relocate SDK files to lib
and update imports
Moved all SDK files from the `sdk` directory to the `lib` directory to better align with project structure. Updated all associated import paths across the codebase to reflect this change. Removed unused or commented-out code in `SiteCoordinator.js` for better clarity and maintainability.
This commit is contained in:

committed by
Geoff Seemueller

parent
fc22278b58
commit
335e8eff11
@@ -7,24 +7,10 @@ export default class SiteCoordinator extends DurableObject {
|
|||||||
this.env = env;
|
this.env = env;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public method to calculate dynamic max tokens
|
|
||||||
async dynamicMaxTokens(input, maxOuputTokens) {
|
async dynamicMaxTokens(input, maxOuputTokens) {
|
||||||
return 2000;
|
return 2000;
|
||||||
// const baseTokenLimit = 1024;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// const { encode } = await import("gpt-tokenizer/esm/model/gpt-4o");
|
|
||||||
//
|
|
||||||
// const inputTokens = Array.isArray(input)
|
|
||||||
// ? encode(input.map(i => i.content).join(' '))
|
|
||||||
// : encode(input);
|
|
||||||
//
|
|
||||||
// const scalingFactor = inputTokens.length > 300 ? 1.5 : 1;
|
|
||||||
//
|
|
||||||
// return Math.min(baseTokenLimit + Math.floor(inputTokens.length * scalingFactor^2), maxOuputTokens);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public method to retrieve conversation history
|
|
||||||
async getConversationHistory(conversationId) {
|
async getConversationHistory(conversationId) {
|
||||||
const history = await this.env.KV_STORAGE.get(
|
const history = await this.env.KV_STORAGE.get(
|
||||||
`conversations:${conversationId}`,
|
`conversations:${conversationId}`,
|
||||||
@@ -33,7 +19,6 @@ export default class SiteCoordinator extends DurableObject {
|
|||||||
return JSON.parse(history) || [];
|
return JSON.parse(history) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public method to save a message to the conversation history
|
|
||||||
async saveConversationHistory(conversationId, message) {
|
async saveConversationHistory(conversationId, message) {
|
||||||
const history = await this.getConversationHistory(conversationId);
|
const history = await this.getConversationHistory(conversationId);
|
||||||
history.push(message);
|
history.push(message);
|
||||||
@@ -52,7 +37,6 @@ export default class SiteCoordinator extends DurableObject {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// New method to get stream data
|
|
||||||
async getStreamData(streamId) {
|
async getStreamData(streamId) {
|
||||||
const streamEntry = await this.env.KV_STORAGE.get(`streams:${streamId}`);
|
const streamEntry = await this.env.KV_STORAGE.get(`streams:${streamId}`);
|
||||||
if (!streamEntry) {
|
if (!streamEntry) {
|
||||||
@@ -61,7 +45,6 @@ export default class SiteCoordinator extends DurableObject {
|
|||||||
|
|
||||||
const { data, expirationTimestamp } = JSON.parse(streamEntry);
|
const { data, expirationTimestamp } = JSON.parse(streamEntry);
|
||||||
if (Date.now() > expirationTimestamp) {
|
if (Date.now() > expirationTimestamp) {
|
||||||
// await this.state.storage.delete(streamId); // Clean up expired entry
|
|
||||||
await this.deleteStreamData(`streams:${streamId}`);
|
await this.deleteStreamData(`streams:${streamId}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -69,7 +52,6 @@ export default class SiteCoordinator extends DurableObject {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// New method to delete stream data (cleanup)
|
|
||||||
async deleteStreamData(streamId) {
|
async deleteStreamData(streamId) {
|
||||||
await this.env.KV_STORAGE.delete(`streams:${streamId}`);
|
await this.env.KV_STORAGE.delete(`streams:${streamId}`);
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,7 @@ import {
|
|||||||
ModelSnapshotType2,
|
ModelSnapshotType2,
|
||||||
UnionStringArray,
|
UnionStringArray,
|
||||||
} from "mobx-state-tree";
|
} from "mobx-state-tree";
|
||||||
import ChatSdk from "../sdk/chat-sdk";
|
import ChatSdk from "../lib/chat-sdk";
|
||||||
|
|
||||||
export class CerebrasSdk {
|
export class CerebrasSdk {
|
||||||
static async handleCerebrasStream(
|
static async handleCerebrasStream(
|
||||||
|
@@ -7,7 +7,7 @@ import {
|
|||||||
ModelSnapshotType2,
|
ModelSnapshotType2,
|
||||||
UnionStringArray,
|
UnionStringArray,
|
||||||
} from "mobx-state-tree";
|
} from "mobx-state-tree";
|
||||||
import ChatSdk from "../sdk/chat-sdk";
|
import ChatSdk from "../lib/chat-sdk";
|
||||||
|
|
||||||
export class ClaudeChatSdk {
|
export class ClaudeChatSdk {
|
||||||
private static async streamClaudeResponse(
|
private static async streamClaudeResponse(
|
||||||
|
@@ -6,7 +6,7 @@ import {
|
|||||||
ModelSnapshotType2,
|
ModelSnapshotType2,
|
||||||
UnionStringArray,
|
UnionStringArray,
|
||||||
} from "mobx-state-tree";
|
} from "mobx-state-tree";
|
||||||
import ChatSdk from "../sdk/chat-sdk";
|
import ChatSdk from "../lib/chat-sdk";
|
||||||
|
|
||||||
export class CloudflareAISdk {
|
export class CloudflareAISdk {
|
||||||
static async handleCloudflareAIStream(
|
static async handleCloudflareAIStream(
|
||||||
|
@@ -9,7 +9,7 @@ import {
|
|||||||
UnionStringArray,
|
UnionStringArray,
|
||||||
} from "mobx-state-tree";
|
} from "mobx-state-tree";
|
||||||
import Message from "../models/Message";
|
import Message from "../models/Message";
|
||||||
import ChatSdk from "../sdk/chat-sdk";
|
import ChatSdk from "../lib/chat-sdk";
|
||||||
|
|
||||||
export class FireworksAiChatSdk {
|
export class FireworksAiChatSdk {
|
||||||
private static async streamFireworksResponse(
|
private static async streamFireworksResponse(
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { OpenAI } from "openai";
|
import { OpenAI } from "openai";
|
||||||
import ChatSdk from "../sdk/chat-sdk";
|
import ChatSdk from "../lib/chat-sdk";
|
||||||
import { StreamParams } from "../services/ChatService";
|
import { StreamParams } from "../services/ChatService";
|
||||||
|
|
||||||
export class GoogleChatSdk {
|
export class GoogleChatSdk {
|
||||||
|
@@ -6,7 +6,7 @@ import {
|
|||||||
ModelSnapshotType2,
|
ModelSnapshotType2,
|
||||||
UnionStringArray,
|
UnionStringArray,
|
||||||
} from "mobx-state-tree";
|
} from "mobx-state-tree";
|
||||||
import ChatSdk from "../sdk/chat-sdk";
|
import ChatSdk from "../lib/chat-sdk";
|
||||||
|
|
||||||
export class GroqChatSdk {
|
export class GroqChatSdk {
|
||||||
static async handleGroqStream(
|
static async handleGroqStream(
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { OpenAI } from "openai";
|
import { OpenAI } from "openai";
|
||||||
import ChatSdk from "../sdk/chat-sdk";
|
import ChatSdk from "../lib/chat-sdk";
|
||||||
|
|
||||||
export class OpenAiChatSdk {
|
export class OpenAiChatSdk {
|
||||||
static async handleOpenAiStream(
|
static async handleOpenAiStream(
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { OpenAI } from "openai";
|
import { OpenAI } from "openai";
|
||||||
import ChatSdk from "../sdk/chat-sdk";
|
import ChatSdk from "../lib/chat-sdk";
|
||||||
|
|
||||||
export class XaiChatSdk {
|
export class XaiChatSdk {
|
||||||
static async handleXaiStream(
|
static async handleXaiStream(
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import {flow, getSnapshot, types} from 'mobx-state-tree';
|
import {flow, getSnapshot, types} from 'mobx-state-tree';
|
||||||
import OpenAI from 'openai';
|
import OpenAI from 'openai';
|
||||||
import ChatSdk from '../sdk/chat-sdk';
|
import ChatSdk from '../lib/chat-sdk';
|
||||||
import Message from "../models/Message";
|
import Message from "../models/Message";
|
||||||
import O1Message from "../models/O1Message";
|
import O1Message from "../models/O1Message";
|
||||||
import {getModelFamily, ModelFamily} from "../../../src/components/chat/lib/SupportedModels";
|
import {getModelFamily, ModelFamily} from "../../../src/components/chat/lib/SupportedModels";
|
||||||
@@ -8,7 +8,7 @@ import {OpenAiChatSdk} from "../providers/openai";
|
|||||||
import {GroqChatSdk} from "../providers/groq";
|
import {GroqChatSdk} from "../providers/groq";
|
||||||
import {ClaudeChatSdk} from "../providers/claude";
|
import {ClaudeChatSdk} from "../providers/claude";
|
||||||
import {FireworksAiChatSdk} from "../providers/fireworks";
|
import {FireworksAiChatSdk} from "../providers/fireworks";
|
||||||
import handleStreamData from "../sdk/handleStreamData";
|
import handleStreamData from "../lib/handleStreamData";
|
||||||
import {GoogleChatSdk} from "../providers/google";
|
import {GoogleChatSdk} from "../providers/google";
|
||||||
import {XaiChatSdk} from "../providers/xai";
|
import {XaiChatSdk} from "../providers/xai";
|
||||||
import {CerebrasSdk} from "../providers/cerebras";
|
import {CerebrasSdk} from "../providers/cerebras";
|
||||||
|
Reference in New Issue
Block a user