-
Notifications
You must be signed in to change notification settings - Fork 1.1k
azure/bedrock api integration #1048
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
76cc39b
28f4b6e
1a415bb
04fb315
8eccd56
c6a752d
2931804
2f3b8b9
be8b7a4
27c722c
69c3d93
467dade
0735ca3
76b44ae
18937ee
0af4acf
c762944
4bd7412
ce07cfa
06ae0e6
9fe40fd
938b51c
607b4c3
adec13c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -739,6 +739,7 @@ ${scriptContent} \ | |
const result = await this.api.act({ | ||
...observeResult, | ||
frameId: this.rootFrameId, | ||
modelClientOptions: this.stagehand["modelClientOptions"], | ||
}); | ||
this.stagehand.addToHistory("act", observeResult, result); | ||
return result; | ||
|
@@ -836,7 +837,10 @@ ${scriptContent} \ | |
if (!instructionOrOptions) { | ||
let result: ExtractResult<T>; | ||
if (this.api) { | ||
result = await this.api.extract<T>({ frameId: this.rootFrameId }); | ||
result = await this.api.extract<T>({ | ||
frameId: this.rootFrameId, | ||
modelClientOptions: this.stagehand["modelClientOptions"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes because otherwise it doesn't get sent to the API. We need this param on all api calls now |
||
}); | ||
} else { | ||
result = await this.extractHandler.extract(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,6 @@ export class StagehandAPI { | |
|
||
async init({ | ||
modelName, | ||
modelApiKey, | ||
domSettleTimeoutMs, | ||
verbose, | ||
debugDom, | ||
|
@@ -59,11 +58,6 @@ export class StagehandAPI { | |
browserbaseSessionCreateParams, | ||
browserbaseSessionID, | ||
}: StartSessionParams): Promise<StartSessionResult> { | ||
if (!modelApiKey) { | ||
throw new StagehandAPIError("modelApiKey is required"); | ||
} | ||
this.modelApiKey = modelApiKey; | ||
|
||
const region = browserbaseSessionCreateParams?.region; | ||
if (region && region !== "us-west-2") { | ||
return { sessionId: browserbaseSessionID ?? null, available: false }; | ||
|
@@ -186,10 +180,19 @@ export class StagehandAPI { | |
const queryString = urlParams.toString(); | ||
const url = `/sessions/${this.sessionId}/${method}${queryString ? `?${queryString}` : ""}`; | ||
|
||
const response = await this.request(url, { | ||
method: "POST", | ||
body: JSON.stringify(args), | ||
}); | ||
// Extract modelClientOptions from args if present | ||
const modelClientOptions = ( | ||
args as { modelClientOptions?: Record<string, unknown> } | ||
)?.modelClientOptions; | ||
|
||
const response = await this.request( | ||
url, | ||
{ | ||
method: "POST", | ||
body: JSON.stringify(args), | ||
}, | ||
modelClientOptions, | ||
); | ||
|
||
if (!response.ok) { | ||
const errorBody = await response.text(); | ||
|
@@ -248,6 +251,7 @@ export class StagehandAPI { | |
private async request( | ||
path: string, | ||
options: RequestInit = {}, | ||
modelClientOptions?: Record<string, unknown>, | ||
): Promise<Response> { | ||
const defaultHeaders: Record<string, string> = { | ||
"x-bb-api-key": this.apiKey, | ||
|
@@ -261,6 +265,12 @@ export class StagehandAPI { | |
"x-sdk-version": STAGEHAND_VERSION, | ||
}; | ||
|
||
// Add modelClientOptions as a header if provided | ||
if (modelClientOptions) { | ||
defaultHeaders["x-model-client-options"] = | ||
JSON.stringify(modelClientOptions); | ||
|
||
} | ||
|
||
if (options.method === "POST" && options.body) { | ||
defaultHeaders["Content-Type"] = "application/json"; | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||
import OpenAI from "openai"; | ||||||
import { CreateChatCompletionResponseError } from "@/types/stagehandErrors"; | ||||||
import type { ClientOptions } from "openai"; | ||||||
|
import type { ClientOptions } from "openai"; | |
clientOptions?: ClientOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need this once we add self-healing