Skip to content

Commit

Permalink
Minor formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
igooch committed Mar 7, 2024
1 parent 243e132 commit d3af7c8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
15 changes: 8 additions & 7 deletions examples/simple-genai-server/gameserver_npcchat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ spec:
env:
- name: GenAiEndpoint
# Use the service endpoint address when running in the same cluster as the inference server.
# TODO (igooch): Change this to the `/genai/npc-chat` endpoint when it's properly plumbed in the inference server
value: "http://npc-chat-api.genai.svc.cluster.local:80"
# GenAiContext is not passed to the npc-chat-api endpoint.
- name: GenAiNpc # False by default. Use GenAiNpc "true" when using the npc-chat-api as the GenAiEndpoint.
Expand All @@ -40,7 +41,7 @@ spec:
- name: ToID # Default is "1".
value: "1"
- name: SimEndpoint
value: "http://vertex-chat-api.genai.svc.cluster.local:80"
value: "http://192.1.1.2/genai/chat"
- name: SimContext
value: "Ask questions about one of the following: What happened here? Where were you during the earthquake? Do you have supplies?"
- name: SimNpc
Expand All @@ -57,9 +58,9 @@ spec:
memory: 64Mi
cpu: 20m
# Schedule onto the game server node pool when running in the same cluster as the inference server.
tolerations:
- key: "agones.dev/role"
value: "gameserver"
effect: "NoExecute"
nodeSelector:
agones.dev/role: gameserver
# tolerations:
# - key: "agones.dev/role"
# value: "gameserver"
# effect: "NoExecute"
# nodeSelector:
# agones.dev/role: gameserver
64 changes: 32 additions & 32 deletions examples/simple-genai-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,71 +38,71 @@ import (
func main() {
sigCtx, _ := signals.NewSigKillContext()

port := flag.String("port", "7654", "The port to listen to traffic on")
genAiEndpoint := flag.String("GenAiEndpoint", "", "The full base URL to send API requests to simulate computer (NPC) responses to user input")
genAiContext := flag.String("GenAiContext", "", "Context for the GenAI endpoint")
prompt := flag.String("Prompt", "", "The first prompt for the GenAI endpoint")
simEndpoint := flag.String("SimEndpoint", "", "The full base URL to send API requests to simulate user input")
simContext := flag.String("SimContext", "", "Context for the Sim endpoint")
numChats := flag.Int("NumChats", 1, "Number of back and forth chats between the sim and genAI")
genAiNpc := flag.Bool("GenAiNpc", false, "Set to true if the GenAIEndpoint is the npc-chat-api endpoint")
simNpc := flag.Bool("SimNpc", false, "Set to true if the SimEndpoint is the npc-chat-api endpoint")
fromID := flag.Int("FromID", 2, "Entity sending messages to the npc-chat-api")
toID := flag.Int("ToID", 1, "Entity receiving messages on the npc-chat-api (the NPC's ID)")
PORT := flag.String("port", "7654", "The port to listen to traffic on")
GEN_AI_ENDPOINT := flag.String("GenAiEndpoint", "", "The full base URL to send API requests to simulate computer (NPC) responses to user input")
GEN_AI_CONTEXT := flag.String("GenAiContext", "", "Context for the GenAI endpoint")
PROMPT := flag.String("Prompt", "", "The first prompt for the GenAI endpoint")
SIM_ENDPOINT := flag.String("SimEndpoint", "", "The full base URL to send API requests to simulate user input")
SIM_CONTEXT := flag.String("SimContext", "", "Context for the Sim endpoint")
NUM_CHATS := flag.Int("NumChats", 1, "Number of back and forth chats between the sim and genAI")
GEN_AI_NPC := flag.Bool("GenAiNpc", false, "Set to true if the GenAIEndpoint is the npc-chat-api endpoint")
SIM_NPC := flag.Bool("SimNpc", false, "Set to true if the SimEndpoint is the npc-chat-api endpoint")
FROM_ID := flag.Int("FromID", 2, "Entity sending messages to the npc-chat-api")
TO_ID := flag.Int("ToID", 1, "Entity receiving messages on the npc-chat-api (the NPC's ID)")

flag.Parse()
if ep := os.Getenv("PORT"); ep != "" {
port = &ep
PORT = &ep
}
if sc := os.Getenv("SimContext"); sc != "" {
simContext = &sc
SIM_CONTEXT = &sc
}
if gac := os.Getenv("GenAiContext"); gac != "" {
genAiContext = &gac
GEN_AI_CONTEXT = &gac
}
if p := os.Getenv("Prompt"); p != "" {
prompt = &p
PROMPT = &p
}
if se := os.Getenv("SimEndpoint"); se != "" {
simEndpoint = &se
SIM_ENDPOINT = &se
}
if gae := os.Getenv("GenAiEndpoint"); gae != "" {
genAiEndpoint = &gae
GEN_AI_ENDPOINT = &gae
}
if nc := os.Getenv("NumChats"); nc != "" {
num, err := strconv.Atoi(nc)
if err != nil {
log.Fatalf("Could not parse NumChats: %v", err)
}
numChats = &num
NUM_CHATS = &num
}
if gan := os.Getenv("GenAiNpc"); gan != "" {
gnpc, err := strconv.ParseBool(gan)
if err != nil {
log.Fatalf("Could parse GenAiNpc: %v", err)
}
genAiNpc = &gnpc
GEN_AI_NPC = &gnpc
}
if sn := os.Getenv("SimNpc"); sn != "" {
snpc, err := strconv.ParseBool(sn)
if err != nil {
log.Fatalf("Could parse GenAiNpc: %v", err)
}
simNpc = &snpc
SIM_NPC = &snpc
}
if fid := os.Getenv("FromID"); fid != "" {
num, err := strconv.Atoi(fid)
if err != nil {
log.Fatalf("Could not parse FromID: %v", err)
}
fromID = &num
FROM_ID = &num
}
if tid := os.Getenv("ToID"); tid != "" {
num, err := strconv.Atoi(tid)
if err != nil {
log.Fatalf("Could not parse ToID: %v", err)
}
toID = &num
TO_ID = &num
}

log.Print("Creating SDK instance")
Expand All @@ -115,16 +115,16 @@ func main() {
go doHealth(s, sigCtx)

var simConn *connection
if *simEndpoint != "" {
log.Printf("Creating Sim Client at endpoint %s", *simEndpoint)
simConn = initClient(*simEndpoint, *simContext, "Sim", *simNpc, *fromID, *toID)
if *SIM_ENDPOINT != "" {
log.Printf("Creating Sim Client at endpoint %s", *SIM_ENDPOINT)
simConn = initClient(*SIM_ENDPOINT, *SIM_CONTEXT, "Sim", *SIM_NPC, *FROM_ID, *TO_ID)
}

if *genAiEndpoint == "" {
if *GEN_AI_ENDPOINT == "" {
log.Fatalf("GenAiEndpoint must be specified")
}
log.Printf("Creating GenAI Client at endpoint %s", *genAiEndpoint)
genAiConn := initClient(*genAiEndpoint, *genAiContext, "GenAI", *genAiNpc, *fromID, *toID)
log.Printf("Creating GenAI Client at endpoint %s", *GEN_AI_ENDPOINT)
genAiConn := initClient(*GEN_AI_ENDPOINT, *GEN_AI_CONTEXT, "GenAI", *GEN_AI_NPC, *FROM_ID, *TO_ID)

log.Print("Marking this server as ready")
if err := s.Ready(); err != nil {
Expand All @@ -133,15 +133,15 @@ func main() {

// Start up TCP listener so the user can interact with the GenAI endpoint manually
if simConn == nil {
go tcpListener(*port, genAiConn)
go tcpListener(*PORT, genAiConn)
<-sigCtx.Done()
} else {
log.Printf("Starting autonomous chat with Prompt: %s", *prompt)
log.Printf("Starting autonomous chat with Prompt: %s", *PROMPT)
var wg sync.WaitGroup
// TODO: Add flag for creating X number of chats
wg.Add(1)
chatHistory := []Message{{Author: simConn.name, Content: *prompt}}
go autonomousChat(*prompt, genAiConn, simConn, *numChats, &wg, sigCtx, chatHistory)
chatHistory := []Message{{Author: simConn.name, Content: *PROMPT}}
go autonomousChat(*PROMPT, genAiConn, simConn, *NUM_CHATS, &wg, sigCtx, chatHistory)
wg.Wait()
}

Expand Down

0 comments on commit d3af7c8

Please sign in to comment.