Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 NEW: Request headers #37

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/langbase/src/common/request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Headers} from './../../types'; // Ensure this import is correct
import {APIConnectionError, APIError} from './errors';
import {Stream} from './stream';
import 'dotenv/config';

interface RequestOptions {
endpoint: string;
Expand All @@ -14,6 +15,7 @@ interface RequestConfig {
apiKey: string;
baseUrl: string;
timeout?: number;
id?: string;
}

interface SendOptions extends RequestOptions {
Expand All @@ -34,9 +36,11 @@ interface HandleGenerateResponseParams {

export class Request {
private config: RequestConfig;
private demo: string = '';

constructor(config: RequestConfig) {
this.config = config;
this.demo = process.env.LB_DEMO || '';
}

// Main send function
Expand Down Expand Up @@ -82,6 +86,8 @@ export class Request {
return {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.config.apiKey}`,
'lb-meta-external-user-id': this.config.id || '',
'lb-demo-id': this.demo,
...headers,
};
}
Expand Down
7 changes: 6 additions & 1 deletion packages/langbase/src/pipes/pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,19 @@ export interface StreamChunk {
export interface PipeOptions {
apiKey: string;
baseUrl?: string;
id?: string;
}

export class Pipe {
private request: Request;

constructor(options: PipeOptions) {
const baseUrl = 'https://api.langbase.com';
this.request = new Request({apiKey: options.apiKey, baseUrl});
this.request = new Request({
baseUrl,
id: options.id,
apiKey: options.apiKey,
});
}

async generateText(options: GenerateOptions): Promise<GenerateResponse> {
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"ASSISTANT_ID",
"INKEEP_API_KEY",
"INKEEP_INTEGRATION_ID",
"VERCEL_URL"
"VERCEL_URL",
"LB_DEMO"
],
"outputs": [
"dist/**",
Expand Down
Loading