Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
T
TeleLlama3 Bot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohamadbashar.disoki
TeleLlama3 Bot
Commits
9e7cb993
Commit
9e7cb993
authored
Apr 29, 2024
by
Mohamad Bashar Desoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate with llama 3
parent
9b53736c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
Bot.java
src/main/java/org/example/Bot.java
+4
-0
llama3.java
src/main/java/org/example/llama3.java
+58
-0
No files found.
src/main/java/org/example/Bot.java
View file @
9e7cb993
...
@@ -25,6 +25,10 @@ public class Bot extends TelegramLongPollingBot {
...
@@ -25,6 +25,10 @@ public class Bot extends TelegramLongPollingBot {
var
user
=
msg
.
getFrom
();
var
user
=
msg
.
getFrom
();
var
id
=
user
.
getId
();
var
id
=
user
.
getId
();
llama3
l3
=
new
llama3
();
prompts
=
msg
.
getText
();
String
resp
=
l3
.
llmChat
(
msg
.
getText
());
sendText
(
id
,
resp
+
" \n \uD83D\uDC50\uD83C\uDFFB back at ya! \uD83D\uDE0A"
);
System
.
out
.
println
(
user
.
getFirstName
()
+
" wrote "
+
msg
.
getText
());
System
.
out
.
println
(
user
.
getFirstName
()
+
" wrote "
+
msg
.
getText
());
}
}
...
...
src/main/java/org/example/llama3.java
0 → 100644
View file @
9e7cb993
package
org
.
example
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
public
class
llama3
{
public
String
llmChat
(
String
chat
){
String
prompt
=
"{\n"
+
// " \"systemPrompt\": \" العب دور مساعد تقني يتحدث اللغة العربية بفصاحة \",\n" +
// " \"user\": \" مرحبا\",\n" +
// " \"Assistant\": \" أهلا، أسألني عن أحدث التقنيات لأجيبك\",\n" +
" \"prompt\": \""
+
chat
+
"\"\n"
+
"}"
;
String
response
=
null
;
response
=
sendRequestToAPI
(
prompt
);
// System.out.println(response);
String
jsonString
=
""
;
jsonString
=
response
.
toString
().
substring
(
0
,
response
.
length
()-
51
);
return
jsonString
;
}
public
String
sendRequestToAPI
(
String
prompt
)
{
try
{
URL
url
=
new
URL
(
"https://fumes-api.onrender.com/llama3"
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setRequestMethod
(
"POST"
);
connection
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
connection
.
setDoOutput
(
true
);
try
(
OutputStream
os
=
connection
.
getOutputStream
())
{
byte
[]
input
=
prompt
.
getBytes
(
"utf-8"
);
os
.
write
(
input
,
0
,
input
.
length
);
}
StringBuilder
response
=
new
StringBuilder
();
try
(
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
(),
"utf-8"
)))
{
String
responseLine
=
null
;
while
((
responseLine
=
br
.
readLine
())
!=
null
)
{
response
.
append
(
responseLine
.
trim
());
}
}
connection
.
disconnect
();
String
responseBody
=
response
.
toString
();
// System.out.println(responseBody);
return
responseBody
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment