Skip to content

Commit

Permalink
feat: rename the env key for model name
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyutaotao committed Jul 25, 2024
1 parent 81cdd1d commit c74d994
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/midscene/src/ai-model/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ import wrapper from 'langsmith/wrappers';
import { AIResponseFormat } from '@/types';

const envConfigKey = 'MIDSCENE_OPENAI_INIT_CONFIG_JSON';
const envModelKey = 'MIDSCENE_OPENAI_MODEL';
const envModelKey = 'MIDSCENE_MODEL_NAME';
const envSmithDebug = 'MIDSCENE_LANGSMITH_DEBUG';

async function createOpenAI() {
let extraConfig: ClientOptions = {};
let extraConfig: ClientOptions = {};
if (typeof process.env[envConfigKey] === 'string') {
console.log('will use env config for openai');
extraConfig = JSON.parse(process.env[envConfigKey]);
}

if (typeof process.env[envConfigKey] === 'string') {
console.log('will use env config for openai');
extraConfig = JSON.parse(process.env[envConfigKey]);
} else if (!process.env.OPENAI_API_KEY) {
console.warn('OPENAI_API is missing');
}
let model = 'gpt-4o';
if (typeof process.env[envModelKey] === 'string') {
console.log(`will use model: ${process.env[envModelKey]}`);
model = process.env[envModelKey];
}

async function createOpenAI() {
const openai = new OpenAI(extraConfig);

if (process.env[envSmithDebug]) {
Expand All @@ -35,7 +38,7 @@ export async function call(
): Promise<string> {
const openai = await createOpenAI();
const completion = await openai.chat.completions.create({
model: process.env[envModelKey] || 'gpt-4o',
model,
messages,
response_format: { type: responseFormat },
});
Expand Down
Binary file modified packages/midscene/tests/fixtures/heytea.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c74d994

Please sign in to comment.