package com.easyagents.agent.runtime.agentscope;

import com.easyagents.agent.runtime.model.AgentGenerationOptions;
import com.easyagents.agent.runtime.model.AgentModelSpec;
import io.agentscope.core.message.Msg;
import io.agentscope.core.message.TextBlock;
import io.agentscope.core.model.ChatResponse;
import io.agentscope.core.model.GenerateOptions;
import io.agentscope.core.model.Model;
import io.agentscope.core.model.ToolSchema;
import reactor.core.publisher.Flux;

import java.util.List;

/**
 * 避免网络调用的测试模型工厂。
 */
class FakeAgentScopeModelFactory extends AgentScopeModelFactory {

    @Override
    public Model create(AgentModelSpec modelSpec, AgentGenerationOptions generationOptions) {
        return new FakeModel(modelSpec == null ? "fake" : modelSpec.getModelName());
    }

    private static class FakeModel implements Model {

        private final String modelName;

        private FakeModel(String modelName) {
            this.modelName = modelName;
        }

        @Override
        public Flux<ChatResponse> stream(List<Msg> messages, List<ToolSchema> toolSchemas, GenerateOptions options) {
            return Flux.just(ChatResponse.builder()
                    .id("fake-response")
                    .content(List.of(TextBlock.builder().text("fake answer").build()))
                    .finishReason("stop")
                    .build());
        }

        @Override
        public String getModelName() {
            return modelName;
        }
    }
}
