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
1af678eb
Commit
1af678eb
authored
1 year ago
by
Huu Le (Lee)
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Feat: add local pdf file option (#441)
parent
220fdb4d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
create-app.ts
+2
-0
2 additions, 0 deletions
create-app.ts
helpers/index.ts
+23
-12
23 additions, 12 deletions
helpers/index.ts
helpers/types.ts
+1
-0
1 addition, 0 deletions
helpers/types.ts
index.ts
+1
-0
1 addition, 0 deletions
index.ts
questions.ts
+84
-12
84 additions, 12 deletions
questions.ts
with
111 additions
and
24 deletions
create-app.ts
+
2
−
0
View file @
1af678eb
...
...
@@ -35,6 +35,7 @@ export async function createApp({
vectorDb
,
externalPort
,
postInstallAction
,
contextFile
,
}:
InstallAppArgs
):
Promise
<
void
>
{
const
root
=
path
.
resolve
(
appPath
);
...
...
@@ -77,6 +78,7 @@ export async function createApp({
vectorDb
,
externalPort
,
postInstallAction
,
contextFile
,
};
if
(
frontend
)
{
...
...
This diff is collapsed.
Click to expand it.
helpers/index.ts
+
23
−
12
View file @
1af678eb
...
...
@@ -70,22 +70,32 @@ const copyTestData = async (
engine
?:
TemplateEngine
,
openAiKey
?:
string
,
vectorDb
?:
TemplateVectorDB
,
contextFile
?:
string
,
// eslint-disable-next-line max-params
)
=>
{
if
(
engine
===
"
context
"
)
{
const
srcPath
=
path
.
join
(
__dirname
,
"
..
"
,
"
templates
"
,
"
components
"
,
"
data
"
,
);
const
destPath
=
path
.
join
(
root
,
"
data
"
);
console
.
log
(
`\nCopying test data to
${
cyan
(
destPath
)}
\n`
);
await
copy
(
"
**
"
,
destPath
,
{
parents
:
true
,
cwd
:
srcPath
,
});
if
(
contextFile
)
{
console
.
log
(
`\nCopying provided file to
${
cyan
(
destPath
)}
\n`
);
await
fs
.
mkdir
(
destPath
,
{
recursive
:
true
});
await
fs
.
copyFile
(
contextFile
,
path
.
join
(
destPath
,
path
.
basename
(
contextFile
)),
);
}
else
{
const
srcPath
=
path
.
join
(
__dirname
,
"
..
"
,
"
templates
"
,
"
components
"
,
"
data
"
,
);
console
.
log
(
`\nCopying test data to
${
cyan
(
destPath
)}
\n`
);
await
copy
(
"
**
"
,
destPath
,
{
parents
:
true
,
cwd
:
srcPath
,
});
}
}
if
(
packageManager
&&
engine
===
"
context
"
)
{
...
...
@@ -168,6 +178,7 @@ export const installTemplate = async (
props
.
engine
,
props
.
openAiKey
,
props
.
vectorDb
,
props
.
contextFile
,
);
}
else
{
// this is a frontend for a full-stack app, create .env file with model information
...
...
This diff is collapsed.
Click to expand it.
helpers/types.ts
+
1
−
0
View file @
1af678eb
...
...
@@ -15,6 +15,7 @@ export interface InstallTemplateArgs {
template
:
TemplateType
;
framework
:
TemplateFramework
;
engine
:
TemplateEngine
;
contextFile
?:
string
;
ui
:
TemplateUI
;
eslint
:
boolean
;
customApiPath
?:
string
;
...
...
This diff is collapsed.
Click to expand it.
index.ts
+
1
−
0
View file @
1af678eb
...
...
@@ -240,6 +240,7 @@ async function run(): Promise<void> {
vectorDb
:
program
.
vectorDb
,
externalPort
:
program
.
externalPort
,
postInstallAction
:
program
.
postInstallAction
,
contextFile
:
program
.
contextFile
,
});
conf
.
set
(
"
preferences
"
,
preferences
);
...
...
This diff is collapsed.
Click to expand it.
questions.ts
+
84
−
12
View file @
1af678eb
import
{
execSync
}
from
"
child_process
"
;
import
ciInfo
from
"
ci-info
"
;
import
fs
from
"
fs
"
;
import
path
from
"
path
"
;
import
{
blue
,
green
}
from
"
picocolors
"
;
import
{
blue
,
green
,
red
}
from
"
picocolors
"
;
import
prompts
from
"
prompts
"
;
import
{
InstallAppArgs
}
from
"
./create-app
"
;
import
{
TemplateFramework
}
from
"
./helpers
"
;
...
...
@@ -9,6 +10,22 @@ import { COMMUNITY_OWNER, COMMUNITY_REPO } from "./helpers/constant";
import
{
getRepoRootFolders
}
from
"
./helpers/repo
"
;
export
type
QuestionArgs
=
Omit
<
InstallAppArgs
,
"
appPath
"
|
"
packageManager
"
>
;
const
MACOS_FILE_SELECTION_SCRIPT
=
`
osascript -l JavaScript -e '
a = Application.currentApplication();
a.includeStandardAdditions = true;
a.chooseFile({ withPrompt: "Please select a file to process:" }).toString()
'`
;
const
WINDOWS_FILE_SELECTION_SCRIPT
=
`
Add-Type -AssemblyName System.Windows.Forms
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.InitialDirectory = [Environment]::GetFolderPath('Desktop')
$result = $openFileDialog.ShowDialog()
if ($result -eq 'OK') {
$openFileDialog.FileName
}
`
;
const
defaults
:
QuestionArgs
=
{
template
:
"
streaming
"
,
...
...
@@ -55,6 +72,45 @@ const getVectorDbChoices = (framework: TemplateFramework) => {
return
displayedChoices
;
};
const
selectPDFFile
=
async
()
=>
{
// Popup to select a PDF file
try
{
let
selectedFilePath
:
string
=
""
;
switch
(
process
.
platform
)
{
case
"
win32
"
:
// Windows
selectedFilePath
=
execSync
(
WINDOWS_FILE_SELECTION_SCRIPT
,
{
shell
:
"
powershell.exe
"
,
})
.
toString
()
.
trim
();
break
;
case
"
darwin
"
:
// MacOS
selectedFilePath
=
execSync
(
MACOS_FILE_SELECTION_SCRIPT
)
.
toString
()
.
trim
();
break
;
default
:
// Unsupported OS
console
.
log
(
red
(
"
Unsupported OS error!
"
));
process
.
exit
(
1
);
}
// Check is pdf file
if
(
!
selectedFilePath
.
endsWith
(
"
.pdf
"
))
{
console
.
log
(
red
(
"
Unsupported file error! Please select a valid PDF file!
"
),
);
process
.
exit
(
1
);
}
return
selectedFilePath
;
}
catch
(
error
)
{
console
.
log
(
red
(
"
Got error when trying to select file! Please try again or select other options.
"
,
),
);
process
.
exit
(
1
);
}
};
export
const
onPromptState
=
(
state
:
any
)
=>
{
if
(
state
.
aborted
)
{
// If we don't re-enable the terminal cursor before exiting
...
...
@@ -243,24 +299,40 @@ export const askQuestions = async (
if
(
ciInfo
.
isCI
)
{
program
.
engine
=
getPrefOrDefault
(
"
engine
"
);
}
else
{
const
{
engine
}
=
await
prompts
(
let
choices
=
[
{
title
:
"
No data, just a simple chat
"
,
value
:
"
simple
"
,
},
{
title
:
"
Use an example PDF
"
,
value
:
"
exampleFile
"
},
];
if
(
process
.
platform
===
"
win32
"
||
process
.
platform
===
"
darwin
"
)
{
choices
.
push
({
title
:
"
Use a local PDF file
"
,
value
:
"
localFile
"
});
}
const
{
dataSource
}
=
await
prompts
(
{
type
:
"
select
"
,
name
:
"
engin
e
"
,
name
:
"
dataSourc
e
"
,
message
:
"
Which data source would you like to use?
"
,
choices
:
[
{
title
:
"
No data, just a simple chat
"
,
value
:
"
simple
"
,
},
{
title
:
"
Use an example PDF
"
,
value
:
"
context
"
},
],
choices
:
choices
,
initial
:
1
,
},
handlers
,
);
program
.
engine
=
engine
;
preferences
.
engine
=
engine
;
switch
(
dataSource
)
{
case
"
simple
"
:
program
.
engine
=
"
simple
"
;
break
;
case
"
exampleFile
"
:
program
.
engine
=
"
context
"
;
break
;
case
"
localFile
"
:
program
.
engine
=
"
context
"
;
// If the user selected the "pdf" option, ask them to select a file
program
.
contextFile
=
await
selectPDFFile
();
break
;
}
}
if
(
program
.
engine
!==
"
simple
"
&&
!
program
.
vectorDb
)
{
if
(
ciInfo
.
isCI
)
{
...
...
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