Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8be0615
Added go server
priankakariat Oct 4, 2024
4be4456
Added readme for go server
priankakariat Oct 4, 2024
95b2d7e
Fixed documentation and read me of go files
priankakariat Oct 4, 2024
a7bc461
Updated readme for go server
priankakariat Oct 4, 2024
0231060
Updated documentation of json.go
priankakariat Oct 4, 2024
bb41cba
Updated formatting of license in go files
priankakariat Oct 4, 2024
233135c
Added cors middleware handler to go server
priankakariat Oct 4, 2024
c2ffef4
Fixed readme for go server
priankakariat Oct 4, 2024
c0b4793
Update README.md
priankakariat Oct 4, 2024
e6ae3ac
Update README.md
priankakariat Oct 4, 2024
b6e7341
Update README.md to skip to manual install for Go
priankakariat Oct 4, 2024
6b4c610
Update README.md
priankakariat Oct 4, 2024
f8cb2af
Update README.md
priankakariat Oct 4, 2024
a4d7518
Update README.md
priankakariat Oct 4, 2024
f2328a4
Update README.md
priankakariat Oct 4, 2024
9e82320
Update README.md
priankakariat Oct 4, 2024
9e383b5
Update README.md
priankakariat Oct 4, 2024
873f294
Update README.md
priankakariat Oct 4, 2024
7f68b8d
Update README.md
priankakariat Oct 4, 2024
7235a45
Update README.md
priankakariat Oct 4, 2024
61dbb0f
Update README.md
priankakariat Oct 4, 2024
af01e1f
Update README.md
priankakariat Oct 4, 2024
54e4b23
Update README.md
priankakariat Oct 4, 2024
46a2d48
Updated documentation of main.go
priankakariat Oct 4, 2024
5c5a7fd
Merge branch 'server-go' of https://github.com/priankakariatyml/examp…
priankakariat Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed documentation and read me of go files
  • Loading branch information
priankakariat committed Oct 4, 2024
commit 95b2d7e7761db78c9a81fca889b325a3be115e1a
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ You must set the API key as an environment variable while running the applicatio
GOOGLE_API_KEY=<your_api_key> go run.
```
The server will start on `localhost:9000`.
By default, the app will run on port 9000. You can modify the port the server listens to by setting the environment variable `PORT`.
By default, the app will run on port 9000. You can modify the port the server listens on by setting the environment variable `PORT`.

## Usage
To start using the app, visit [http://localhost:3000](http://localhost:3000/)
Expand Down
2 changes: 1 addition & 1 deletion server-go/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Gemini chat app with Go

## Install Go
To run this app Go must be installed on your system.
To run this app, Go must be installed on your system.
Check if Go is already installed.
```
go version
Expand Down
6 changes: 3 additions & 3 deletions server-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
const modelName = "gemini-1.5-flash"
const defaultPort = "9000"

// Server state holding the context of the gemini client and the generative model.
// Server state holding the context of the Gemini client and the generative model.
type geminiServer struct {
ctx context.Context
model *genai.GenerativeModel
Expand Down Expand Up @@ -100,7 +100,7 @@ func (gs *geminiServer) chatHandler(w http.ResponseWriter, r *http.Request) {
// - chat: string,
// - history: Array,
//
// Partial responses from the model is text.
// A partial response from the model is text.
func (gs *geminiServer) streamingChatHandler(w http.ResponseWriter, r *http.Request) {
cr := &chatRequest{}
if err := parseRequestJSON(r, cr); err != nil {
Expand Down Expand Up @@ -143,7 +143,7 @@ func (gs *geminiServer) startChat(hist []content) *genai.ChatSession {
return cs
}

// encodeHistory converts []content to a []*genai.Content which is accepted by the model's chat session.
// encodeHistory converts []content to a []*genai.Content that is accepted by the model's chat session.
func encodeHistory(cs []content) []*genai.Content {
gcs := make([]*genai.Content, len(cs))
for i, c := range cs {
Expand Down