Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cat-disruptor-6500
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
cat-disruptor-6500
Commits
3d83f522
Commit
3d83f522
authored
1 year ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
refactor
parent
afd9c755
No related branches found
Branches containing commit
No related tags found
Loading
Checking pipeline status
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/handlers/llama.rs
+56
-46
56 additions, 46 deletions
src/handlers/llama.rs
with
56 additions
and
46 deletions
src/handlers/llama.rs
+
56
−
46
View file @
3d83f522
...
@@ -54,6 +54,60 @@ impl LlamaHandler {
...
@@ -54,6 +54,60 @@ impl LlamaHandler {
Ok
(
resp
)
Ok
(
resp
)
}
}
async
fn
list_models
(
&
self
,
ctx
:
&
Context
,
msg
:
&
Message
)
{
let
people
=
self
.models
.keys
()
.map
(|
x
|
format!
(
"- {x}"
))
.collect
::
<
Vec
<
_
>>
()
.join
(
"
\n
"
);
if
let
Err
(
e
)
=
msg
.reply
(
ctx
,
format!
(
"Available models:
\n
{}"
,
people
))
.await
{
eprintln!
(
"{:?}"
,
e
);
}
}
async
fn
reply
(
&
self
,
ctx
:
&
Context
,
msg
:
&
Message
,
model
:
&
str
,
txt
:
&
str
)
{
if
txt
.is_empty
()
{
return
;
}
let
_typing
=
try_or_log
(||
Typing
::
start
(
ctx
.http
.clone
(),
msg
.channel_id
.0
));
let
resp
=
self
.call_llama
(
model
,
txt
)
.await
;
let
resp
=
match
resp
.as_ref
()
{
Ok
(
x
)
=>
x
,
Err
(
e
)
=>
{
eprintln!
(
"{e:?}"
);
"Could not communicate with Llama. Check the server logs for more details."
}
};
let
resp
=
if
resp
.is_empty
()
{
"[No response]"
}
else
{
resp
};
// discord messages are limited to 2000 codepoints
let
chunks
:
Vec
<
String
>
=
resp
.chars
()
.chunks
(
2000
)
.into_iter
()
.map
(|
chunk
|
chunk
.collect
())
.collect
();
for
chunk
in
chunks
{
if
let
Err
(
e
)
=
msg
.reply
(
ctx
,
chunk
)
.await
{
eprintln!
(
"{e:?}"
);
}
}
}
}
}
#[async_trait]
#[async_trait]
...
@@ -68,58 +122,14 @@ impl LineHandler for LlamaHandler {
...
@@ -68,58 +122,14 @@ impl LineHandler for LlamaHandler {
let
txt
=
&
msg
.content
;
let
txt
=
&
msg
.content
;
if
txt
.starts_with
(
"!people"
)
{
if
txt
.starts_with
(
"!people"
)
{
let
people
=
self
self
.list_models
(
ctx
,
msg
)
.await
;
.models
.keys
()
.map
(|
x
|
format!
(
"- {x}"
))
.collect
::
<
Vec
<
_
>>
()
.join
(
"
\n
"
);
if
let
Err
(
e
)
=
msg
.reply
(
ctx
,
format!
(
"Available models:
\n
{}"
,
people
))
.await
{
eprintln!
(
"{:?}"
,
e
);
}
return
;
return
;
}
}
for
(
name
,
model
)
in
&
self
.models
{
for
(
name
,
model
)
in
&
self
.models
{
if
let
Some
(
txt
)
=
txt
.strip_prefix
(
&
format!
(
"!{name} "
))
{
if
let
Some
(
txt
)
=
txt
.strip_prefix
(
&
format!
(
"!{name} "
))
{
if
txt
.is_empty
()
{
self
.reply
(
ctx
,
msg
,
model
,
txt
)
.await
;
return
;
}
let
_typing
=
try_or_log
(||
Typing
::
start
(
ctx
.http
.clone
(),
msg
.channel_id
.0
));
let
resp
=
self
.call_llama
(
model
,
txt
)
.await
;
let
resp
=
match
resp
.as_ref
()
{
Ok
(
x
)
=>
x
,
Err
(
e
)
=>
{
eprintln!
(
"{e:?}"
);
"Could not communicate with Llama. Check the server logs for more details."
}
};
let
resp
=
if
resp
.is_empty
()
{
"[No response]"
}
else
{
resp
};
let
chunks
:
Vec
<
String
>
=
resp
.chars
()
.chunks
(
2000
)
.into_iter
()
.map
(|
chunk
|
chunk
.collect
())
.collect
();
for
chunk
in
chunks
{
if
let
Err
(
e
)
=
msg
.reply
(
ctx
,
chunk
)
.await
{
eprintln!
(
"{e:?}"
);
}
}
return
;
return
;
}
}
...
...
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