Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LlamaIndexTS
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
LlamaIndexTS
Commits
d8fe65a2
Commit
d8fe65a2
authored
1 year ago
by
Marcus Schiesser
Browse files
Options
Downloads
Patches
Plain Diff
refactor: improved var naming
parent
ba1cb996
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/create-llama/templates/python.ts
+19
-15
19 additions, 15 deletions
packages/create-llama/templates/python.ts
with
19 additions
and
15 deletions
packages/create-llama/templates/python.ts
+
19
−
15
View file @
d8fe65a2
...
@@ -5,17 +5,17 @@ import { parse, stringify } from "smol-toml";
...
@@ -5,17 +5,17 @@ import { parse, stringify } from "smol-toml";
import
{
copy
}
from
"
../helpers/copy
"
;
import
{
copy
}
from
"
../helpers/copy
"
;
import
{
InstallTemplateArgs
,
TemplateVectorDB
}
from
"
./types
"
;
import
{
InstallTemplateArgs
,
TemplateVectorDB
}
from
"
./types
"
;
interface
I
Dependency
Item
{
interface
Dependency
{
name
:
string
;
name
:
string
;
version
:
string
;
version
:
string
;
}
}
const
get
PythonAddOn
Dependencies
=
(
vectorDb
?:
TemplateVectorDB
)
=>
{
const
get
Additional
Dependencies
=
(
vectorDb
?:
TemplateVectorDB
)
=>
{
const
addOnD
ependencies
:
I
Dependency
Item
[]
=
[];
const
d
ependencies
:
Dependency
[]
=
[];
switch
(
vectorDb
)
{
switch
(
vectorDb
)
{
case
"
mongo
"
:
{
case
"
mongo
"
:
{
addOnD
ependencies
.
push
({
d
ependencies
.
push
({
name
:
"
pymongo
"
,
name
:
"
pymongo
"
,
version
:
"
^4.6.1
"
,
version
:
"
^4.6.1
"
,
});
});
...
@@ -23,25 +23,26 @@ const getPythonAddOnDependencies = (vectorDb?: TemplateVectorDB) => {
...
@@ -23,25 +23,26 @@ const getPythonAddOnDependencies = (vectorDb?: TemplateVectorDB) => {
}
}
}
}
return
addOnD
ependencies
;
return
d
ependencies
;
};
};
const
preparePythonDependencies
=
async
(
root
:
string
,
const
addDependencies
=
async
(
addOnDependencies
:
IDependencyItem
[],
projectDir
:
string
,
dependencies
:
Dependency
[],
)
=>
{
)
=>
{
if
(
addOnD
ependencies
.
length
===
0
)
return
;
if
(
d
ependencies
.
length
===
0
)
return
;
const
FILENAME
=
"
pyproject.toml
"
;
const
FILENAME
=
"
pyproject.toml
"
;
try
{
try
{
// Parse toml file
// Parse toml file
const
file
=
path
.
join
(
ro
ot
,
FILENAME
);
const
file
=
path
.
join
(
p
ro
jectDir
,
FILENAME
);
const
fileContent
=
await
fs
.
readFile
(
file
,
"
utf8
"
);
const
fileContent
=
await
fs
.
readFile
(
file
,
"
utf8
"
);
const
fileParsed
=
parse
(
fileContent
);
const
fileParsed
=
parse
(
fileContent
);
// Modify toml dependencies
// Modify toml dependencies
const
tool
=
fileParsed
.
tool
as
any
;
const
tool
=
fileParsed
.
tool
as
any
;
const
dependencies
=
tool
.
poetry
.
dependencies
as
any
;
const
dependencies
=
tool
.
poetry
.
dependencies
as
any
;
for
(
const
dependency
of
addOnD
ependencies
)
{
for
(
const
dependency
of
d
ependencies
)
{
dependencies
[
dependency
.
name
]
=
dependency
.
version
;
dependencies
[
dependency
.
name
]
=
dependency
.
version
;
}
}
...
@@ -49,16 +50,19 @@ const preparePythonDependencies = async (
...
@@ -49,16 +50,19 @@ const preparePythonDependencies = async (
const
newFileContent
=
stringify
(
fileParsed
);
const
newFileContent
=
stringify
(
fileParsed
);
await
fs
.
writeFile
(
file
,
newFileContent
);
await
fs
.
writeFile
(
file
,
newFileContent
);
const
dependenciesString
=
addOnDependencies
.
map
((
d
)
=>
d
.
name
).
join
(
"
,
"
);
const
dependenciesString
=
dependencies
.
map
((
d
:
Dependency
)
=>
d
.
name
)
.
join
(
"
,
"
);
console
.
log
(
`\nAdded
${
dependenciesString
}
to
${
cyan
(
FILENAME
)}
\n`
);
console
.
log
(
`\nAdded
${
dependenciesString
}
to
${
cyan
(
FILENAME
)}
\n`
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
console
.
log
(
`Error wh
en preparing
${
FILENAME
}
file for Python template
\n`
,
`Error wh
ile updating dependencies for Poetry project file
${
FILENAME
}
\n`
,
error
,
error
,
);
);
console
.
log
(
error
);
console
.
log
(
error
);
}
}
};
};
export
const
installPythonTemplate
=
async
({
export
const
installPythonTemplate
=
async
({
root
,
root
,
template
,
template
,
...
@@ -105,8 +109,8 @@ export const installPythonTemplate = async ({
...
@@ -105,8 +109,8 @@ export const installPythonTemplate = async ({
});
});
}
}
const
addOnDependencies
=
get
PythonAddOn
Dependencies
(
vectorDb
);
const
addOnDependencies
=
get
Additional
Dependencies
(
vectorDb
);
await
preparePython
Dependencies
(
root
,
addOnDependencies
);
await
add
Dependencies
(
root
,
addOnDependencies
);
console
.
log
(
console
.
log
(
"
\n
Python project, dependencies won't be installed automatically.
\n
"
,
"
\n
Python project, dependencies won't be installed automatically.
\n
"
,
...
...
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