Skip to content

Commit f3577c5

Browse files
leehuwujmarcusschiesserthucpn
authored
add data scientist use case (directly using uploaded files) (#355)
--------- Co-authored-by: Marcus Schiesser <[email protected]> Co-authored-by: Thuc Pham <[email protected]>
1 parent a5f5c9d commit f3577c5

File tree

29 files changed

+903
-432
lines changed

29 files changed

+903
-432
lines changed

.changeset/poor-knives-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-llama": patch
3+
---
4+
5+
Fix event streaming is blocked

.changeset/wet-tips-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-llama": patch
3+
---
4+
5+
Add upload file to sandbox (artifact and code interpreter)

helpers/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ For better results, you can specify the region parameter to get results from a s
139139
dependencies: [
140140
{
141141
name: "e2b_code_interpreter",
142-
version: "0.0.10",
142+
version: "0.0.11b38",
143143
},
144144
],
145145
supportedFrameworks: ["fastapi", "express", "nextjs"],

questions/simple.ts

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ import { getTools } from "../helpers/tools";
55
import { ModelConfig, TemplateFramework } from "../helpers/types";
66
import { PureQuestionArgs, QuestionResults } from "./types";
77
import { askPostInstallAction, questionHandlers } from "./utils";
8-
type AppType = "rag" | "code_artifact" | "multiagent" | "extractor";
8+
9+
type AppType =
10+
| "rag"
11+
| "code_artifact"
12+
| "multiagent"
13+
| "extractor"
14+
| "data_scientist";
915

1016
type SimpleAnswers = {
1117
appType: AppType;
1218
language: TemplateFramework;
1319
useLlamaCloud: boolean;
1420
llamaCloudKey?: string;
15-
modelConfig: ModelConfig;
1621
};
1722

1823
export const askSimpleQuestions = async (
@@ -25,6 +30,7 @@ export const askSimpleQuestions = async (
2530
message: "What app do you want to build?",
2631
choices: [
2732
{ title: "Agentic RAG", value: "rag" },
33+
{ title: "Data Scientist", value: "data_scientist" },
2834
{ title: "Code Artifact Agent", value: "code_artifact" },
2935
{ title: "Multi-Agent Report Gen", value: "multiagent" },
3036
{ title: "Structured extraction", value: "extractor" },
@@ -80,40 +86,56 @@ export const askSimpleQuestions = async (
8086
}
8187
}
8288

83-
const modelConfig = await askModelConfig({
84-
openAiKey: args.openAiKey,
85-
askModels: args.askModels ?? false,
86-
framework: language,
87-
});
88-
89-
const results = convertAnswers({
89+
const results = await convertAnswers(args, {
9090
appType,
9191
language,
9292
useLlamaCloud,
9393
llamaCloudKey,
94-
modelConfig,
9594
});
9695

9796
results.postInstallAction = await askPostInstallAction(results);
9897
return results;
9998
};
10099

101-
const convertAnswers = (answers: SimpleAnswers): QuestionResults => {
100+
const convertAnswers = async (
101+
args: PureQuestionArgs,
102+
answers: SimpleAnswers,
103+
): Promise<QuestionResults> => {
104+
const MODEL_GPT4o: ModelConfig = {
105+
provider: "openai",
106+
apiKey: args.openAiKey,
107+
model: "gpt-4o",
108+
embeddingModel: "text-embedding-3-large",
109+
dimensions: 1536,
110+
isConfigured(): boolean {
111+
return !!args.openAiKey;
112+
},
113+
};
102114
const lookup: Record<
103115
AppType,
104-
Pick<QuestionResults, "template" | "tools" | "frontend" | "dataSources">
116+
Pick<QuestionResults, "template" | "tools" | "frontend" | "dataSources"> & {
117+
modelConfig?: ModelConfig;
118+
}
105119
> = {
106120
rag: {
107121
template: "streaming",
108122
tools: getTools(["duckduckgo"]),
109123
frontend: true,
110124
dataSources: [EXAMPLE_FILE],
111125
},
126+
data_scientist: {
127+
template: "streaming",
128+
tools: getTools(["interpreter", "document_generator"]),
129+
frontend: true,
130+
dataSources: [],
131+
modelConfig: MODEL_GPT4o,
132+
},
112133
code_artifact: {
113134
template: "streaming",
114135
tools: getTools(["artifact"]),
115136
frontend: true,
116137
dataSources: [],
138+
modelConfig: MODEL_GPT4o,
117139
},
118140
multiagent: {
119141
template: "multiagent",
@@ -140,11 +162,16 @@ const convertAnswers = (answers: SimpleAnswers): QuestionResults => {
140162
llamaCloudKey: answers.llamaCloudKey,
141163
useLlamaParse: answers.useLlamaCloud,
142164
llamapack: "",
143-
postInstallAction: "none",
144165
vectorDb: answers.useLlamaCloud ? "llamacloud" : "none",
145-
modelConfig: answers.modelConfig,
146166
observability: "none",
147167
...results,
168+
modelConfig:
169+
results.modelConfig ??
170+
(await askModelConfig({
171+
openAiKey: args.openAiKey,
172+
askModels: args.askModels ?? false,
173+
framework: answers.language,
174+
})),
148175
frontend: answers.language === "nextjs" ? false : results.frontend,
149176
};
150177
};

templates/components/engines/python/agent/tools/artifact.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,29 @@ class CodeGeneratorTool:
6666
def __init__(self):
6767
pass
6868

69-
def artifact(self, query: str, old_code: Optional[str] = None) -> Dict:
70-
"""Generate a code artifact based on the input.
69+
def artifact(
70+
self,
71+
query: str,
72+
sandbox_files: Optional[List[str]] = None,
73+
old_code: Optional[str] = None,
74+
) -> Dict:
75+
"""Generate a code artifact based on the provided input.
7176
7277
Args:
73-
query (str): The description of the application you want to build.
78+
query (str): A description of the application you want to build.
79+
sandbox_files (Optional[List[str]], optional): A list of sandbox file paths. Defaults to None. Include these files if the code requires them.
7480
old_code (Optional[str], optional): The existing code to be modified. Defaults to None.
7581
7682
Returns:
77-
Dict: A dictionary containing the generated artifact information.
83+
Dict: A dictionary containing information about the generated artifact.
7884
"""
7985

8086
if old_code:
8187
user_message = f"{query}\n\nThe existing code is: \n```\n{old_code}\n```"
8288
else:
8389
user_message = query
90+
if sandbox_files:
91+
user_message += f"\n\nThe provided files are: \n{str(sandbox_files)}"
8492

8593
messages: List[ChatMessage] = [
8694
ChatMessage(role="system", content=CODE_GENERATION_PROMPT),
@@ -90,7 +98,10 @@ def artifact(self, query: str, old_code: Optional[str] = None) -> Dict:
9098
sllm = Settings.llm.as_structured_llm(output_cls=CodeArtifact) # type: ignore
9199
response = sllm.chat(messages)
92100
data: CodeArtifact = response.raw
93-
return data.model_dump()
101+
data_dict = data.model_dump()
102+
if sandbox_files:
103+
data_dict["files"] = sandbox_files
104+
return data_dict
94105
except Exception as e:
95106
logger.error(f"Failed to generate artifact: {str(e)}")
96107
raise e

0 commit comments

Comments
 (0)