Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 0 additions & 8 deletions ai-convert/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ type ModelConfig struct {
TopLogProbs int `json:"top_logprobs,omitempty"`
}

// Message represents a single message in the conversation.
type Message struct {
// Role indicates the role of the message sender (e.g., "system", "user", "assistant").
Role string `json:"role"`
// Content contains the actual text of the message.
Content string `json:"content"`
}

type Error struct {
Message string `json:"message"`
Type string `json:"type"`
Expand Down
3 changes: 3 additions & 0 deletions drivers/app/extend-param.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func newAdditionalParam(params []*Additional) *additionalParam {
}

func (a *additionalParam) Execute(ctx http_service.IHttpContext) error {
if len(a.params) < 1 {
return nil
}
contentType, _, _ := mime.ParseMediaType(ctx.Proxy().Body().ContentType())
bodyParams, formParams, err := parseBodyParams(ctx)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions drivers/output/kafka/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"time"

"github.com/Shopify/sarama"
"github.com/IBM/sarama"
"github.com/eolinker/eosc"
)

Expand Down Expand Up @@ -114,8 +114,10 @@ func (c *Config) doCheck() (*ProducerConfig, error) {
}
// 只监听错误
s.Producer.Return.Errors = true
s.Producer.Return.Successes = false
s.Producer.Return.Successes = true
s.Producer.RequiredAcks = sarama.WaitForLocal
s.Producer.Compression = sarama.CompressionGZIP
s.Producer.CompressionLevel = sarama.CompressionLevelDefault

p.Address = strings.Split(conf.Address, ",")
if len(p.Address) == 0 {
Expand Down
1 change: 0 additions & 1 deletion drivers/output/kafka/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Driver struct {

func Check(v *Config, workers map[eosc.RequireId]eosc.IWorker) error {
_, err := v.doCheck()

return err
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/output/kafka/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/Shopify/sarama"
"github.com/IBM/sarama"
"github.com/eolinker/eosc/log"
)

Expand Down
22 changes: 15 additions & 7 deletions drivers/output/kafka/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"sync"

"github.com/Shopify/sarama"
"github.com/IBM/sarama"
"github.com/eolinker/eosc"
"github.com/eolinker/eosc/formatter"
"github.com/eolinker/eosc/log"
Expand Down Expand Up @@ -69,7 +69,7 @@ func (o *tProducer) close() {
o.cancel()
o.cancel = nil
}
o.producer.AsyncClose()
o.producer.Close()
o.producer = nil
o.formatter = nil
}
Expand All @@ -94,7 +94,6 @@ func (o *tProducer) output(entry eosc.IEntry) error {
}
log.DebugF("kafka send addr: %s, topic: %s, data: %s", o.conf.Address, o.conf.Topic, data)
o.write(msg)

return nil
}

Expand Down Expand Up @@ -122,15 +121,24 @@ func (o *tProducer) work(producer sarama.AsyncProducer, ctx context.Context, cfg
case err := <-producer.Errors():
log.DebugF("receive error.kafka addr: %s,kafka topic: %s,kafka partition: %d", cfg.Address, cfg.Topic, cfg.Partition)
if err != nil {
log.Warnf("kafka error:%s", err.Error())
log.Errorf("kafka error:%s", err.Error())
}
case success, ok := <-producer.Successes():
log.DebugF("receive success.kafka addr: %s,kafka topic: %s,kafka partition: %d", cfg.Address, cfg.Topic, cfg.Partition)
if !ok {
log.Errorf("kafka producer closed")
return
}
log.DebugF("kafka success:%s", success)
log.DebugF("Message sent to partition %d at offset %d\n", success.Partition, success.Offset)
//key, err := success.Key.Encode()
//if err != nil {
// log.Errorf("kafka error:%s", err.Error())
// continue
//}
//value, err := success.Value.Encode()
//if err != nil {
// log.Errorf("kafka error:%s", err.Error())
// continue
//}
//log.DebugF("kafka success addr: %s, topic: %s, partition: %d, key: %s, value: %s", cfg.Address, cfg.Topic, success.Partition, string(key), string(value))
}
}
}
17 changes: 9 additions & 8 deletions drivers/plugins/ai-prompt/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/sashabaranov/go-openai"
"strings"

ai_convert "github.com/eolinker/apinto/ai-convert"
Expand All @@ -15,15 +16,15 @@ import (
)

type RequestMessage struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Variables map[string]string `json:"variables,omitempty"`
Model string `json:"model"`
Messages []openai.ChatCompletionMessage `json:"messages"`
Variables map[string]string `json:"variables,omitempty"`
}

type Message struct {
Role string `json:"role"`
Content string `json:"content"`
}
//type Message struct {
// Role string `json:"role"`
// Content string `json:"content"`
//}

type executor struct {
drivers.WorkerBase
Expand Down Expand Up @@ -112,7 +113,7 @@ func genRequestMessage(ctx http_context.IHttpContext, body []byte, prompt string
}
prompt = strings.Replace(prompt, fmt.Sprintf("{{%s}}", k), baseMsg.Config.Variables[k], -1)
}
messages := []Message{
messages := []openai.ChatCompletionMessage{
{
Role: "system",
Content: prompt,
Expand Down
4 changes: 2 additions & 2 deletions example/dubbo2/client/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import "flag"

var (
address = "127.0.0.1:8099"
address = "127.0.0.1:20000"
)

func init() {
flag.StringVar(&address, "addr", "172.28.187.118:8099", "The address to connect dubbo2 server.")
flag.StringVar(&address, "addr", "127.0.0.1:20000", "The address to connect dubbo2 server.")
flag.Parse()
}
63 changes: 31 additions & 32 deletions example/dubbo2/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ func init() {
func client(addr string, serviceName, methodName string, timeout time.Duration, typesList []string, valuesList []hessian.Object) (interface{}, error) {
arguments := make([]interface{}, 3)
parameterValues := make([]reflect.Value, 3)

arguments[0] = methodName
arguments[1] = typesList
arguments[2] = valuesList

parameterValues[0] = reflect.ValueOf(arguments[0])
parameterValues[1] = reflect.ValueOf(arguments[1])
parameterValues[2] = reflect.ValueOf(arguments[2])

invoc := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("$invoke"),
invocation.WithArguments(arguments),
invocation.WithParameterValues(parameterValues))

url, err := common.NewURL(addr,
common.WithProtocol(dubbo.DUBBO), common.WithParamsValue(constant.SerializationKey, constant.Hessian2Serialization),
//common.WithParamsValue(constant.GenericFilterKey, "true"),
Expand All @@ -47,16 +47,16 @@ func client(addr string, serviceName, methodName string, timeout time.Duration,
return nil, err
}
dubboProtocol := dubbo.NewDubboProtocol()

invoker := dubboProtocol.Refer(url)
var resp interface{}
invoc.SetReply(&resp)

result := invoker.Invoke(context.Background(), invoc)
if result.Error() != nil {
return nil, result.Error()
}

return result.Result(), nil
}

Expand All @@ -71,111 +71,110 @@ func main() {
func ComplexServer() {
var types []string
var valuesList []hessian.Object

types = append(types, "object")

server := map[string]interface{}{"id": 16, "name": "apinto", "email": "[email protected]"}

valuesList = append(valuesList, map[string]interface{}{"time": time.Now(), "addr": "192.168.0.1", "server": server})

resp, err := client(address, "api.Server", "ComplexServer", time.Second*3, types, valuesList)

if err != nil {
logger.Errorf("ComplexServer err=%s", err.Error())
return
}
v := resp.(*interface{})
vvv := formatData(*v)

bytes, _ := json.Marshal(vvv)
logger.Infof("ComplexServer result=%s", string(bytes))
}

func UpdateList() {
var types []string
var valuesList []hessian.Object

types = append(types, "object")
val1 := map[string]interface{}{"id": 16, "name": "apinto", "email": "[email protected]"}
val2 := map[string]interface{}{"id": 16, "name": "apinto", "email": "[email protected]"}
valuesList = append(valuesList, []interface{}{val1, val2})

resp, err := client(address, "api.Server", "UpdateList", time.Second*3, types, valuesList)

if err != nil {
logger.Errorf("UpdateList err=%s", err.Error())
return
}
v := resp.(*interface{})
vvv := formatData(*v)

bytes, _ := json.Marshal(vvv)
logger.Infof("UpdateList result=%s", string(bytes))
}

func Update() {
var types []string
var valuesList []hessian.Object

types = append(types, "object")
valuesList = append(valuesList, map[string]interface{}{"id": 16, "name": "apinto", "email": "[email protected]"})
resp, err := client(address, "api.Server", "Update", time.Second*3, types, valuesList)

if err != nil {
logger.Errorf("Update err=%s", err.Error())
return
}
v := resp.(*interface{})
vvv := formatData(*v)

bytes, _ := json.Marshal(vvv)

logger.Infof("Update result=%s", string(bytes))
}

func List() {
var types []string
var valuesList []hessian.Object

types = append(types, "object")
valuesList = append(valuesList, map[string]interface{}{"id": 16, "name": "apinto", "email": "[email protected]"})
resp, err := client(address, "api.Server", "List", time.Second*3, types, valuesList)

if err != nil {
logger.Errorf("List err=%s", err.Error())
return
}
v := resp.(*interface{})
vvv := formatData(*v)

bytes, _ := json.Marshal(vvv)

logger.Infof("List result=%s", string(bytes))
}

func GetById(id int64) {
types := make([]string, 0)
valuesList := make([]hessian.Object, 0)

types = append(types, "int64")
valuesList = append(valuesList, id)

resp, err := client(address, "api.Server", "GetById", time.Second*3, types, valuesList)

if err != nil {
logger.Errorf("List err=%s", err.Error())
return
}
v := resp.(*interface{})
vvv := formatData(*v)

bytes, _ := json.Marshal(vvv)

logger.Infof("GetById result=%s", string(bytes))
}

func formatData(value interface{}) interface{} {

switch valueTemp := value.(type) {
case map[interface{}]interface{}:
maps := make(map[string]interface{})
Expand All @@ -185,7 +184,7 @@ func formatData(value interface{}) interface{} {
return maps
case []interface{}:
values := make([]interface{}, 0)

for _, v := range valueTemp {
values = append(values, formatData(v))
}
Expand Down
6 changes: 2 additions & 4 deletions example/dubbo2/model/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package model

import "time"

type Server struct {
Id int64
Name string
Expand All @@ -10,7 +8,7 @@ type Server struct {
}

type ComplexServer struct {
Addr string
Time time.Time
Addr string
//Time time.Time
Server Server
}
Loading