Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Create Llama
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Create Llama
Commits
7dac3788
Commit
7dac3788
authored
1 year ago
by
Huu Le (Lee)
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: hardcode "en" as default language for llama-parse and use llama cloud key from env (#614)
parent
51e6e7a6
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.eslintrc
+2
-1
2 additions, 1 deletion
.eslintrc
helpers/index.ts
+30
-9
30 additions, 9 deletions
helpers/index.ts
questions.ts
+12
-7
12 additions, 7 deletions
questions.ts
templates/components/loaders/python/llama_parse/loader.py
+1
-4
1 addition, 4 deletions
templates/components/loaders/python/llama_parse/loader.py
with
45 additions
and
21 deletions
.eslintrc
+
2
−
1
View file @
7dac3788
...
...
@@ -6,6 +6,7 @@
{
"allowList": [
"OPENAI_API_KEY",
"LLAMA_CLOUD_API_KEY",
"npm_config_user_agent",
"http_proxy",
"https_proxy",
...
...
@@ -16,4 +17,4 @@
}
]
}
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
helpers/index.ts
+
30
−
9
View file @
7dac3788
...
...
@@ -52,8 +52,14 @@ const createEnvLocalFile = async (
content
+=
`EMBEDDING_MODEL=
${
opts
?.
embeddingModel
}
\n`
;
}
if
(
opts
?.
llamaCloudKey
)
{
content
+=
`LLAMA_CLOUD_API_KEY=
${
opts
?.
llamaCloudKey
}
\n`
;
if
((
opts
?.
dataSource
?.
config
as
FileSourceConfig
).
useLlamaParse
)
{
if
(
opts
?.
llamaCloudKey
)
{
content
+=
`LLAMA_CLOUD_API_KEY=
${
opts
?.
llamaCloudKey
}
\n`
;
}
else
{
content
+=
`# Please obtain the Llama Cloud API key from https://cloud.llamaindex.ai/api-key
# and set it to the LLAMA_CLOUD_API_KEY variable below.
# LLAMA_CLOUD_API_KEY=`
;
}
}
switch
(
opts
?.
vectorDb
)
{
...
...
@@ -95,22 +101,34 @@ const createEnvLocalFile = async (
}
};
const
generateContextData
=
async
(
// eslint-disable-next-line max-params
async
function
generateContextData
(
framework
:
TemplateFramework
,
packageManager
?:
PackageManager
,
openAiKey
?:
string
,
vectorDb
?:
TemplateVectorDB
,
)
=>
{
dataSource
?:
TemplateDataSource
,
llamaCloudKey
?:
string
,
)
{
if
(
packageManager
)
{
const
runGenerate
=
`
${
cyan
(
framework
===
"
fastapi
"
?
"
poetry run python app/engine/generate.py
"
:
`
${
packageManager
}
run generate`
,
)}
`
;
const
hasOpenAiKey
=
openAiKey
||
process
.
env
[
"
OPENAI_API_KEY
"
];
const
openAiKeyConfigured
=
openAiKey
||
process
.
env
[
"
OPENAI_API_KEY
"
];
const
llamaCloudKeyConfigured
=
(
dataSource
?.
config
as
FileSourceConfig
)
?.
useLlamaParse
?
llamaCloudKey
||
process
.
env
[
"
LLAMA_CLOUD_API_KEY
"
]
:
true
;
const
hasVectorDb
=
vectorDb
&&
vectorDb
!==
"
none
"
;
if
(
framework
===
"
fastapi
"
)
{
if
(
hasOpenAiKey
&&
!
hasVectorDb
&&
isHavingPoetryLockFile
())
{
if
(
openAiKeyConfigured
&&
llamaCloudKeyConfigured
&&
!
hasVectorDb
&&
isHavingPoetryLockFile
()
)
{
console
.
log
(
`Running
${
runGenerate
}
to generate the context data.`
);
const
result
=
tryPoetryRun
(
"
python app/engine/generate.py
"
);
if
(
!
result
)
{
...
...
@@ -121,7 +139,7 @@ const generateContextData = async (
return
;
}
}
else
{
if
(
hasO
penAiKey
&&
vectorDb
===
"
none
"
)
{
if
(
o
penAiKey
Configured
&&
vectorDb
===
"
none
"
)
{
console
.
log
(
`Running
${
runGenerate
}
to generate the context data.`
);
await
callPackageManager
(
packageManager
,
true
,
[
"
run
"
,
"
generate
"
]);
return
;
...
...
@@ -129,14 +147,15 @@ const generateContextData = async (
}
const
settings
=
[];
if
(
!
hasOpenAiKey
)
settings
.
push
(
"
your OpenAI key
"
);
if
(
!
openAiKeyConfigured
)
settings
.
push
(
"
your OpenAI key
"
);
if
(
!
llamaCloudKeyConfigured
)
settings
.
push
(
"
your Llama Cloud key
"
);
if
(
hasVectorDb
)
settings
.
push
(
"
your Vector DB environment variables
"
);
const
settingsMessage
=
settings
.
length
>
0
?
`After setting
${
settings
.
join
(
"
and
"
)}
, `
:
""
;
const
generateMessage
=
`run
${
runGenerate
}
to generate the context data.`
;
console
.
log
(
`\n
${
settingsMessage
}${
generateMessage
}
\n\n`
);
}
}
;
}
const
copyContextData
=
async
(
root
:
string
,
...
...
@@ -234,6 +253,8 @@ export const installTemplate = async (
props
.
packageManager
,
props
.
openAiKey
,
props
.
vectorDb
,
props
.
dataSource
,
props
.
llamaCloudKey
,
);
}
}
...
...
This diff is collapsed.
Click to expand it.
questions.ts
+
12
−
7
View file @
7dac3788
...
...
@@ -221,12 +221,20 @@ export const askQuestions = async (
},
];
const
hasOpenAiKey
=
program
.
openAiKey
||
process
.
env
[
"
OPENAI_API_KEY
"
];
const
openAiKeyConfigured
=
program
.
openAiKey
||
process
.
env
[
"
OPENAI_API_KEY
"
];
// If using LlamaParse, require LlamaCloud API key
const
llamaCloudKeyConfigured
=
(
program
.
dataSource
?.
config
as
FileSourceConfig
)?.
useLlamaParse
?
program
.
llamaCloudKey
||
process
.
env
[
"
LLAMA_CLOUD_API_KEY
"
]
:
true
;
const
hasVectorDb
=
program
.
vectorDb
&&
program
.
vectorDb
!==
"
none
"
;
// Can run the app if all tools do not require configuration
if
(
!
hasVectorDb
&&
hasOpenAiKey
&&
openAiKeyConfigured
&&
llamaCloudKeyConfigured
&&
!
toolsRequireConfig
(
program
.
tools
)
&&
!
program
.
llamapack
)
{
...
...
@@ -605,11 +613,8 @@ export const askQuestions = async (
{
type
:
"
text
"
,
name
:
"
llamaCloudKey
"
,
message
:
"
Please provide your LlamaIndex Cloud API key:
"
,
validate
:
(
value
)
=>
value
?
true
:
"
LlamaIndex Cloud API key is required. You can get it from: https://cloud.llamaindex.ai/api-key
"
,
message
:
"
Please provide your LlamaIndex Cloud API key (leave blank to skip):
"
,
},
handlers
,
);
...
...
This diff is collapsed.
Click to expand it.
templates/components/loaders/python/llama_parse/loader.py
+
1
−
4
View file @
7dac3788
...
...
@@ -5,10 +5,7 @@ DATA_DIR = "data" # directory containing the documents
def
get_documents
():
parser
=
LlamaParse
(
result_type
=
"
markdown
"
,
verbose
=
True
,
)
parser
=
LlamaParse
(
result_type
=
"
markdown
"
,
verbose
=
True
,
language
=
"
en
"
)
reader
=
SimpleDirectoryReader
(
DATA_DIR
,
file_extractor
=
{
"
.pdf
"
:
parser
})
return
reader
.
load_data
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment