写一个githubDemo

1.List组件

<template>
  <div class="container">
    <!-- 展示用户列表 -->
    <div class="row">
      <div
        v-show="info.users.length"
        v-for="(item, index) in info.users"
        :key="item.id"
      >
        <div class="col-sm-4 item">
          <img
            class="hover-image"
            :src="item.avatar_url"
            @click="targetPage(item.html_url)"
          />
          <h5>{{ item.login }}</h5>
        </div>
        <br v-if="isHuanhang(index)" />
      </div>
    </div>

    <!-- 展示欢迎词 -->
    <h1 v-show="info.isFirst">欢迎使用!</h1>
    <!-- 展示加载中 -->
    <h1 v-show="info.isLoading">加载中....</h1>
    <!-- 展示错误信息 -->
    <h1 v-show="info.errMsg">{{ info.errMsg }}</h1>
  </div>
</template>

<script>
export default {
  name: "MyList",
  data() {
    return {
      info: {
        users: [],
        isFirst: true,
        isLoading: false,
        errMsg: "",
      },
    };
  },

  methods: {
    getList(listObj) {
      //1.第一种方式
      // this.info = {...this.info,...listObj};
      //2.第二种方式
      Object.assign(this.info, listObj);
    },
    isHuanhang(index) {
      if (index % 3 === 0) {
        return true;
      } else {
        return false;
      }
    },
    targetPage(url) {
      window.open(url, "_blank");
    },
  },
  mounted() {
    this.$bus.$on("sendList", this.getList);
  },
  beforeDestroy() {
    this.$bus.$off("sendList");
  },
};
</script>

<style scoped>
.item {
  width: 300px;
  height: 150px;
  margin-top: 30px;
  margin-right: 76px;
  padding: 150px;
  display: flex;
  flex-direction: column; /* 纵向排列子项 */
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  border: 1px solid #ccc; /* 可选:给容器加个边框 */
  box-sizing: border-box; /* 包括边框和内边距在内的总宽高 */
}

img {
  width: 150x;
  height: 120px;
}

.hover-image {
  cursor: pointer; /* 设置鼠标悬浮时光标变成手指 */
}
</style>

2.search 组件

<template>
  <div class="container-xl">
    <div class="row bc">
      <div
        class="col-xl search-box d-flex flex-column justify-content-end"
      >
        <h1 class="text-bottom margin-left-dom">Search Github Users</h1>
      </div>
    </div>
    <div class="row bc">
      <div class="col-xl search-box" >
        <div class="input-group mb-3 margin-left-dom inputWidth">
          <input
            type="text"
            class="form-control"
            placeholder="enter the name you search"
            v-model="keyWord"
          />
            <button class="btn btn-outline-dark dom-margin" type="button" @click="searchUsers" >Search</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios';


export default {
  name: "MySearch",
  data() {
    return {
      keyWord:''
    }
  },
  methods:{
    searchUsers(){
         this.$bus.$emit('sendList',{ 
        isFirst: false,
        isLoading: true,
        });


      axios.get('https://api.github.com/search/users',{
        params:{
          q:this.keyWord
        }
      }).then(res=>{
         this.$bus.$emit('sendList',{ 
          users: res.data.items,
        isLoading: false,
        });
      },err=>{
        console.log(err);
        this.$bus.$emit('sendList',{ 
            users: [],
            isLoading: false,
            errMsg: '请求失败,请稍后再试!'
        });
      })
    }

  }
};
</script>

<style scoped>

.bc{
background-color: rgba(13, 14, 14, 0.313);

}

.search-box {
  height: 120px;
}

.margin-left-dom {
  margin-left: 30px;
}

.inputWidth {
  width: 450px;
}
.dom-margin{
  margin-left: 12px;
}
</style>

3.App组件

<template>
  <div id="appContainer">

    <MySearch/>
    <MyList/>
    
  </div>
</template>

<script>

 import MySearch from './components/MySearch.vue'
 import MyList from './components/MyList.vue'
export default {
  name: "App",
  components: {
    MySearch,MyList
  },
  methods:{
 
  }
};
</script>

<style>

</style>

4.引入bootStarp

<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="utf-8">
    <!-- 针对IE浏览器 得一个特殊配置,含义是让IE浏览器以最高得渲染级别渲染页面 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 开启移动端得理想视口 -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <!-- 配置页签图标 -->
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <!-- 配置网页的标题 package.json name:'vue_test'当作网页的标题 -->
     <link rel="stylesheet" href="<%= BASE_URL %>css/bootstrap.css">
    <title><%= htmlWebpackPlugin.options.title %></title>
  </head>
  <body>
    <!-- 当浏览器不支持JS时,noscript中的 元素就会被渲染 -->
    <noscript>
      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <!-- 容器 -->
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

5.展示

好的,我可以用 Java 编一个简单的 demo,来展示如何使用 ChitGPT 进行对话。 首先,你需要从 ChitGPT 的 GitHub 仓库中下载代码,并且安装好所需的依赖。然后,你可以按照以下步骤编 demo: 1. 导入所需的类和包: ```java import java.util.Scanner; import ai.chit.chatbot.ChitChatbot; import ai.chit.chatbot.engine.ChitChatbotEngine; import ai.chit.chatbot.engine.ChitChatbotEngineFactory; import ai.chit.chatbot.engine.ChitChatbotEngineType; import ai.chit.chatbot.util.ChitIOUtils; ``` 2. 创建 ChitGPT 引擎实例: ```java ChitChatbotEngine engine = ChitChatbotEngineFactory.createEngine(ChitChatbotEngineType.GPT); ``` 3. 载入预训练模型: ```java String modelPath = "/path/to/your/model"; engine.loadModel(modelPath); ``` 4. 创建 ChitGPT 对话机器人实例: ```java ChitChatbot chatbot = new ChitChatbot(engine); ``` 5. 开始对话: ```java Scanner scanner = new Scanner(System.in); String input; while (true) { System.out.print("You: "); input = scanner.nextLine().trim(); if (input.equalsIgnoreCase("exit")) { break; } String response = chatbot.getReply(input); System.out.println("Bot: " + response); } ``` 完整的 demo 代码如下: ```java import java.util.Scanner; import ai.chit.chatbot.ChitChatbot; import ai.chit.chatbot.engine.ChitChatbotEngine; import ai.chit.chatbot.engine.ChitChatbotEngineFactory; import ai.chit.chatbot.engine.ChitChatbotEngineType; import ai.chit.chatbot.util.ChitIOUtils; public class ChitGPTDemo { public static void main(String[] args) { ChitChatbotEngine engine = ChitChatbotEngineFactory.createEngine(ChitChatbotEngineType.GPT); String modelPath = "/path/to/your/model"; engine.loadModel(modelPath); ChitChatbot chatbot = new ChitChatbot(engine); Scanner scanner = new Scanner(System.in); String input; while (true) { System.out.print("You: "); input = scanner.nextLine().trim(); if (input.equalsIgnoreCase("exit")) { break; } String response = chatbot.getReply(input); System.out.println("Bot: " + response); } } } ``` 注意,以上代码中的 `"/path/to/your/model"` 应该替换为你本地存放预训练模型的路径。另外,在运行 demo 时需要提供足够的内存,建议至少为 2GB 以上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值