Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Get CodeVisualizer up and running in your VS Code environment in just a few clic
3. **Configure AI Features (Optional)**
- Open Settings: `Ctrl+,` (Windows/Linux) or `Cmd+,` (Mac)
- Search for "CodeVisualizer"
- Enable AI labels and add your API key for supported providers
- Enable AI labels and add your API key for supported providers, including Atlas Cloud
- Or use Ollama for completely local AI processing

4. **Start Visualizing**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"type": "string",
"enum": [
"openai",
"atlascloud",
"gemini",
"groq",
"ollama",
Expand Down
1 change: 1 addition & 0 deletions src/core/llm/LLMManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class LLMManager {
const providerPick = await vscode.window.showQuickPick(
[
{ label: "OpenAI", value: "openai" },
{ label: "Atlas Cloud", value: "atlascloud" },
{ label: "Gemini", value: "gemini" },
{ label: "Groq", value: "groq" },
{ label: "Ollama (local)", value: "ollama" },
Expand Down
31 changes: 23 additions & 8 deletions src/core/llm/LLMService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as crypto from "crypto";
import { logInfo, logWarn, logError } from "./LLMLogger";

export type Provider = "openai" | "gemini" | "groq" | "ollama";
export type Provider = "openai" | "atlascloud" | "gemini" | "groq" | "ollama";

export interface TranslateParams {
mermaidSource: string;
Expand All @@ -19,6 +19,8 @@ export class LLMService {
switch (provider) {
case "openai":
return ["gpt-4o-mini", "gpt-4o", "o3-mini"];
case "atlascloud":
return ["openai/gpt-4.1-mini"];
case "gemini":
return ["gemini-1.5-flash", "gemini-1.5-pro"];
case "groq":
Expand Down Expand Up @@ -266,6 +268,17 @@ async function callProvider(
expectedCount,
labels
);
case "atlascloud":
return await callOpenAI(
model,
apiKey,
systemPrompt,
userPrompt,
expectedCount,
labels,
"https://api.atlascloud.ai/v1/chat/completions",
"Atlas Cloud"
);
case "gemini":
return await callGemini(
model,
Expand Down Expand Up @@ -439,6 +452,8 @@ async function callOpenAI(
userPrompt: string,
expectedCount: number,
referenceLabels: string[],
endpoint = "https://api.openai.com/v1/chat/completions",
providerName = "OpenAI",
): Promise<string[] | null> {
try {
const bodyPayload = {
Expand All @@ -450,7 +465,7 @@ async function callOpenAI(
{ role: "user", content: userPrompt },
],
};
const res = await fetch("https://api.openai.com/v1/chat/completions", {
const res = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -461,7 +476,7 @@ async function callOpenAI(
if (!res.ok) {
const text = await safeReadBody(res);
logWarn(
`OpenAI responded with ${res.status} ${res.statusText}. Body snippet: ${text.substring(
`${providerName} responded with ${res.status} ${res.statusText}. Body snippet: ${text.substring(
0,
500
)}`
Expand All @@ -471,7 +486,7 @@ async function callOpenAI(
const data: unknown = await res.json();
if (!isOpenAIChatCompletionResponse(data)) {
logWarn(
`OpenAI response shape unexpected: ${JSON.stringify(data).substring(
`${providerName} response shape unexpected: ${JSON.stringify(data).substring(
0,
500
)}`
Expand All @@ -483,13 +498,13 @@ async function callOpenAI(
? data.choices[0].message.content
: undefined;
if (!content) {
logWarn("OpenAI response did not contain message content");
logWarn(`${providerName} response did not contain message content`);
return null;
}
const parsed = parseLabelsJsonText(content, expectedCount, referenceLabels);
if (!parsed) {
logWarn(
`OpenAI output could not be parsed as JSON array. Content: ${content.substring(
`${providerName} output could not be parsed as JSON array. Content: ${content.substring(
0,
500
)}`
Expand All @@ -498,7 +513,7 @@ async function callOpenAI(
return parsed;
} catch (err) {
logError(
`OpenAI fetch error: ${err instanceof Error ? err.message : String(err)}`,
`${providerName} fetch error: ${err instanceof Error ? err.message : String(err)}`,
);
return null;
}
Expand Down Expand Up @@ -966,4 +981,4 @@ function sanitizeLabel(label: string): string {
s = s.slice(0, maxLen - 1).trimEnd() + "…";
}
return s;
}
}