mirror of
https://github.com/hazemKrimi/touch-programming.git
synced 2026-05-01 18:20:26 +00:00
Some improvements
This commit is contained in:
@@ -1 +1,3 @@
|
|||||||
/node_modules
|
/node_modules
|
||||||
|
|
||||||
|
.env
|
||||||
|
|||||||
+1
-2
@@ -11,7 +11,7 @@ function App() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async function() {
|
(async function() {
|
||||||
const response = await fetch('http://localhost:5000/generate?lang=julia&lines=10');
|
const response = await fetch(`${import.meta.env.VITE_API_URL}/generate?lang=typescript&lines=20`);
|
||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
|
||||||
@@ -22,7 +22,6 @@ function App() {
|
|||||||
|
|
||||||
if (done) {
|
if (done) {
|
||||||
setLoaded(true);
|
setLoaded(true);
|
||||||
setCode(prev => prev.replace(/\s\n/g, '\n'));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/dlclark/regexp2 v1.11.4 // indirect
|
github.com/dlclark/regexp2 v1.11.4 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
github.com/labstack/gommon v0.4.2 // indirect
|
github.com/labstack/gommon v0.4.2 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
|||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/labstack/echo/v4 v4.13.2 h1:9aAt4hstpH54qIcqkuUXRLTf+v7yOTfMPWzDtuqLmtA=
|
github.com/labstack/echo/v4 v4.13.2 h1:9aAt4hstpH54qIcqkuUXRLTf+v7yOTfMPWzDtuqLmtA=
|
||||||
github.com/labstack/echo/v4 v4.13.2/go.mod h1:uc9gDtHB8UWt3FfbYx0HyxcCuvR4YuPYOxF/1QjoV/c=
|
github.com/labstack/echo/v4 v4.13.2/go.mod h1:uc9gDtHB8UWt3FfbYx0HyxcCuvR4YuPYOxF/1QjoV/c=
|
||||||
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
||||||
|
|||||||
+24
-4
@@ -5,8 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
"github.com/tmc/langchaingo/llms"
|
"github.com/tmc/langchaingo/llms"
|
||||||
@@ -14,6 +16,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
err := godotenv.Load()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error loading environment!")
|
||||||
|
}
|
||||||
|
|
||||||
|
LLM_MODEL := os.Getenv("LLM_MODEL")
|
||||||
|
PORT := os.Getenv("PORT")
|
||||||
|
|
||||||
|
if len(LLM_MODEL) == 0 {
|
||||||
|
log.Fatal("No LLM model specified in environment!")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(PORT) == 0 {
|
||||||
|
PORT = "8080"
|
||||||
|
}
|
||||||
|
|
||||||
ech := echo.New()
|
ech := echo.New()
|
||||||
|
|
||||||
ech.Use(middleware.CORS())
|
ech.Use(middleware.CORS())
|
||||||
@@ -33,17 +52,18 @@ func main() {
|
|||||||
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||||
ctx.Response().WriteHeader(http.StatusOK)
|
ctx.Response().WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
llm, err := ollama.New(ollama.WithModel("llama3.1:8b"))
|
llm, err := ollama.New(ollama.WithModel(fmt.Sprintf("%s", LLM_MODEL)))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Clean the prompt result of any unnecessary formatting or text
|
||||||
ollamaCtx := context.Background()
|
ollamaCtx := context.Background()
|
||||||
content := []llms.MessageContent{
|
content := []llms.MessageContent{
|
||||||
llms.TextParts(llms.ChatMessageTypeSystem, `You are only a code generator. You must not respond with anything else but code and do not format with code fences. Always use spaces instead of tabs.`),
|
llms.TextParts(llms.ChatMessageTypeSystem, `You must only generate code without any descriptions. Also don't include any code comments and use spaces instead of tabs for spacing. Most importantly. Most importantly you must remove any markdown code fences that wrap the content!`),
|
||||||
llms.TextParts(llms.ChatMessageTypeHuman, fmt.Sprintf(`
|
llms.TextParts(llms.ChatMessageTypeHuman, fmt.Sprintf(`
|
||||||
Generate max %d lines of code without any unncessary formatting from a well known open source project in the %s programming language.`, lines, lang)),
|
Generate a maximum of %d lines of code from a well known open source project in the %s programming language.`, lines, lang)),
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := llm.GenerateContent(ollamaCtx, content, llms.WithStreamingFunc(func(streamCtx context.Context, chunk []byte) error {
|
if _, err := llm.GenerateContent(ollamaCtx, content, llms.WithStreamingFunc(func(streamCtx context.Context, chunk []byte) error {
|
||||||
@@ -58,5 +78,5 @@ func main() {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
ech.Logger.Fatal(ech.Start(":5000"))
|
ech.Logger.Fatal(ech.Start(fmt.Sprintf(":%s", PORT)))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user