-
-
Save JAICHANGPARK/da30af4dcdf2684fa789fa6eae3d6622 to your computer and use it in GitHub Desktop.
GOOGLE_API_KEY= |
if err := godotenv.Load(); err != nil { | |
log.Fatal("No .env file found") | |
} | |
// Loads the API Key from environment | |
// Loads the API key from environment | |
apiKey := os.Getenv("GOOGLE_API_KEY") | |
if apiKey == "" { | |
log.Fatal("Set your GOOGLE_API_KEY environment variable in the .env file") | |
} |
package main | |
import ( | |
"context" | |
"log" | |
"os" | |
"github.com/joho/godotenv" | |
"github.com/tmc/langchaingo/chains" | |
"github.com/tmc/langchaingo/llms/googleai" | |
"github.com/tmc/langchaingo/prompts" | |
) | |
func main() { | |
if err := godotenv.Load(); err != nil { | |
log.Fatal("No .env file found") | |
} | |
apiKey := os.Getenv("GOOGLE_API_KEY") | |
if apiKey == "" { | |
log.Fatal("Set your GOOGLE_API_KEY environment variable in the .env file") | |
} | |
ctx := context.Background() | |
llm, err := googleai.New(ctx, googleai.WithAPIKey(apiKey), | |
googleai.WithDefaultModel("gemini-2.5-flash-preview-04-17")) | |
if err != nil { | |
log.Fatal(err) | |
} | |
prompt := "strawberry에는 r이 몇개 포함되어 있는지 알아?" | |
completion, err := llms.GenerateFromSinglePrompt(ctx, llm, prompt) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(completion) | |
} |
package main | |
import ( | |
"context" | |
"log" | |
"os" | |
"github.com/joho/godotenv" | |
"github.com/tmc/langchaingo/chains" | |
"github.com/tmc/langchaingo/llms/googleai" | |
"github.com/tmc/langchaingo/prompts" | |
) | |
func main() { | |
if err := godotenv.Load(); err != nil { | |
log.Fatal("No .env file found") | |
} | |
apiKey := os.Getenv("GOOGLE_API_KEY") | |
if apiKey == "" { | |
log.Fatal("Set your GOOGLE_API_KEY environment variable in the .env file") | |
} | |
ctx := context.Background() | |
llm, err := googleai.New(ctx, googleai.WithAPIKey(apiKey), | |
googleai.WithDefaultModel("gemini-2.5-flash-preview-04-17")) | |
if err != nil { | |
log.Fatal(err) | |
} | |
prompt := prompts.NewPromptTemplate( | |
`You are a helpful AI assistant: | |
Question: {{.question}}`, | |
[]string{"question"}) | |
llmChain := chains.NewLLMChain(llm, prompt) | |
const question = "How do I get started genai?" | |
inputs := map[string]interface{}{ | |
"question": question, | |
} | |
out, err := chains.Call(ctx, llmChain, inputs) | |
if err != nil { | |
log.Fatalf("Failed to run LLM chain: %v", err) | |
} | |
responseText, ok := out["text"].(string) | |
if !ok { | |
log.Println("Unexpected response type") | |
return | |
} | |
log.Println("Question:", question) | |
log.Println("Generated Answer:", responseText) | |
} |
llm, err := googleai.New(ctx, googleai.WithAPIKey(apiKey), | |
googleai.WithDefaultEmbeddingModel("gemini-embedding-exp-03-07")) | |
if err != nil { | |
log.Fatal(err) | |
} | |
texts := []string{"딥러닝과 머신러닝의 차이", "동해물과 백두산이 마르고 닳도록"} | |
emb, err := llm.CreateEmbedding(ctx, texts) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("Num of embedding vectors:", len(emb)) | |
for i, e := range emb { | |
fmt.Printf("%d: %v...\n", i, e[:10]) | |
} |
go get github.com/joho/godotenv
go get github.com/tmc/langchaingo/chains
go get github.com/tmc/langchaingo/llms/googleai
go get github.com/tmc/langchaingo/prompts
재미있고 유익한 세션 감사드립니다.
질문 1) 이런 에이전트 개발 시 파이썬보다 Golang 만의 강점이 있을까요? 핸즈온 세션을 보니 성능의 문제는 추론 서버의 응답 같아서요.
질문 2) Golang 질문인데, 실무에서 프로젝트 구조화같은 협업을 위한 Go 컨벤션은 커뮤니티를 많이 따라가나요? 아니면 자체적으로 구축해서 사용하나요?
질문 3) 고랭에서 context drilling 같은 부분은 모니터링을 어떤식으로 할까요?? 자바에서는 thread local id 같은게 있다고 들었습니다.
질문 4) Eino 를 활용해서 프로젝트 하나 해보고 싶은데, 역시 에이전트 프로젝트가 나을까요?
@Jeffr-K 좋은 질문 감사합니다.
질문 1) 이런 에이전트 개발 시 파이썬보다 Golang 만의 강점이 있을까요? 핸즈온 세션을 보니 성능의 문제는 추론 서버의 응답 같아서요.
Golang은 Python과 달리 컴파일 언어이기도 하고 정적 타입 언어로, 컴파일 시점에 많은 오류를 잡아낼 수 있어요. Python에 비해 일반적으로 메모리 사용량이 적고 실행 속도가 빠릅니다. 특히 동시성 처리와 메모리 관리 효율성에서 강점을 보입니다.
질문 2) Golang 질문인데, 실무에서 프로젝트 구조화같은 협업을 위한 Go 컨벤션은 커뮤니티를 많이 따라가나요? 아니면 자체적으로 구축해서 사용하나요?
질문에 대한 정답은 없다고 보네요. 널리 알려진 커뮤니티의 표준과 패턴을 적극적으로 수용하고 이해한 뒤, 팀과 프로젝트의 상황에 맞게 선택, 조합, 확장하여 내부 표준으로 발전시켜 나가는 방식이 가장 효과적이고 일반적이지 않을까 생각합니다.
질문 3) 고랭에서 context drilling 같은 부분은 모니터링을 어떤식으로 할까요?? 자바에서는 thread local id 같은게 있다고 들었습니다.
OpenTelemetry 를 활용하는 방법도 있을거 같네요.
질문 4) Eino 를 활용해서 프로젝트 하나 해보고 싶은데, 역시 에이전트 프로젝트가 나을까요?
프로젝트에서 어떤 것(What)을 구현할지 계획을 잘 정하신 뒤에 Agents가 필요한지 검토(How)해보시는 방향도 좋을거 같아요.
go run main.go
2025/05/10 12:58:45 Question: How do I get started genai?
2025/05/10 12:58:45 Generated Answer: Okay, "GenAI" stands for Generative AI. Getting started with it can mean different things depending on your goal. Here are a few common ways to approach it, from simplest to more technical:
Path 1: Just Using Existing GenAI Tools (Easiest)
Path 2: Learning the Concepts Behind GenAI
Path 3: Learning to Build/Develop with GenAI
General Tips for Getting Started:
Choose the path that aligns best with your interests and current skills, and just start exploring!