-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: optimistic search page loading and improved content refinement
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
395 additions
and
175 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { type IncomingHttpHeaders } from 'node:http' | ||
import { createHash } from 'node:crypto' | ||
|
||
export interface ModelProviderCredentials { | ||
baseUrl: string | ||
apiKey: string | ||
} | ||
|
||
export function getModelProviderCredentials(headers: IncomingHttpHeaders): ModelProviderCredentials | undefined { | ||
const baseUrl = getGPTScriptEnv(headers, 'OPENAI_BASE_URL')?.trim() | ||
if (!baseUrl) return undefined | ||
|
||
const apiKey = getGPTScriptEnv(headers, 'OPENAI_API_KEY')?.trim() | ||
if (!apiKey) return undefined | ||
|
||
return { baseUrl, apiKey } | ||
} | ||
|
||
export function getSessionId(headers: IncomingHttpHeaders): string { | ||
const workspaceId = getGPTScriptEnv(headers, 'GPTSCRIPT_WORKSPACE_ID') | ||
if (!workspaceId?.trim()) throw new Error('No GPTScript workspace ID provided') | ||
|
||
return createHash('sha256').update(workspaceId).digest('hex').substring(0, 16) | ||
} | ||
|
||
export function getGPTScriptEnv(headers: IncomingHttpHeaders, envKey: string): string | undefined { | ||
const envHeader = headers?.['x-gptscript-env'] | ||
const envArray = Array.isArray(envHeader) ? envHeader : [envHeader] | ||
|
||
for (const env of envArray) { | ||
if (env == null) continue | ||
for (const pair of env.split(',')) { | ||
const [key, value] = pair.split('=').map((part) => part.trim()) | ||
if (key === envKey) return value | ||
} | ||
} | ||
return undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.